Use constant names for G-codes like M600, M601 and "tool_change"(Change extruder)
This commit is contained in:
parent
7a22e43825
commit
6c8bb51f4a
@ -1692,7 +1692,7 @@ void GCode::process_layer(
|
||||
int m600_before_extruder = -1;
|
||||
while (!m_custom_g_code_heights.empty() && m_custom_g_code_heights.front().height-EPSILON < layer.print_z) {
|
||||
custom_code = m_custom_g_code_heights.front().gcode;
|
||||
if (custom_code == "M600" && m_custom_g_code_heights.front().extruder > 0)
|
||||
if (custom_code == ColorChangeCode && m_custom_g_code_heights.front().extruder > 0)
|
||||
m600_before_extruder = m_custom_g_code_heights.front().extruder - 1;
|
||||
m_custom_g_code_heights.erase(m_custom_g_code_heights.begin());
|
||||
colorprint_change = true;
|
||||
@ -1710,11 +1710,11 @@ void GCode::process_layer(
|
||||
// gcode += "M600\n";
|
||||
// }
|
||||
|
||||
// don't save "tool_change" code to GCode
|
||||
if (colorprint_change && custom_code != "tool_change") {
|
||||
// don't save "tool_change"(ExtruderChangeCode) code to GCode
|
||||
if (colorprint_change && custom_code != ExtruderChangeCode) {
|
||||
const bool single_material_print = print.config().nozzle_diameter.size() == 1;
|
||||
|
||||
if (custom_code == "M600") // color change
|
||||
if (custom_code == ColorChangeCode) // color change
|
||||
{
|
||||
// add tag for analyzer
|
||||
gcode += "; " + GCodeAnalyzer::Color_Change_Tag + ",T" + std::to_string(m600_before_extruder) + "\n";
|
||||
@ -1732,7 +1732,7 @@ void GCode::process_layer(
|
||||
}
|
||||
else
|
||||
{
|
||||
if (custom_code == "M601") // Pause print
|
||||
if (custom_code == PausePrintCode) // Pause print
|
||||
{
|
||||
// add tag for analyzer
|
||||
gcode += "; " + GCodeAnalyzer::Pause_Print_Tag + "\n";
|
||||
@ -1750,16 +1750,16 @@ void GCode::process_layer(
|
||||
}
|
||||
|
||||
/*
|
||||
if (single_material_print || custom_code != "tool_change")
|
||||
if (single_material_print || custom_code != ExtruderChangeCode)
|
||||
{
|
||||
// add tag for analyzer
|
||||
gcode += "; " + GCodeAnalyzer::Color_Change_Tag + "\n";
|
||||
// add tag for time estimator
|
||||
gcode += "; " + GCodeTimeEstimator::Color_Change_Tag + "\n";
|
||||
if (single_material_print && custom_code == "tool_change")
|
||||
custom_code = "M600";
|
||||
if (single_material_print && custom_code == ExtruderChangeCode)
|
||||
custom_code = ColorChangeCode;
|
||||
|
||||
if (!single_material_print && custom_code == "M600" &&
|
||||
if (!single_material_print && custom_code == ColorChangeCode &&
|
||||
m600_before_extruder >= 0 && first_extruder_id != m600_before_extruder
|
||||
// && !MMU1
|
||||
) {
|
||||
|
@ -591,7 +591,7 @@ std::vector<std::pair<double, DynamicPrintConfig>> Model::get_custom_tool_change
|
||||
std::vector<std::pair<double, DynamicPrintConfig>> custom_tool_changes;
|
||||
if (!custom_gcode_per_height.empty()) {
|
||||
for (const CustomGCode& custom_gcode : custom_gcode_per_height)
|
||||
if (custom_gcode.gcode == "tool_change") {
|
||||
if (custom_gcode.gcode == ExtruderChangeCode) {
|
||||
DynamicPrintConfig config;
|
||||
// If extruder count in PrinterSettings was changed, use default (0) extruder for extruders, more than num_extruders
|
||||
config.set_key_value("extruder", new ConfigOptionInt(custom_gcode.extruder > num_extruders ? 0 : custom_gcode.extruder));
|
||||
|
@ -71,6 +71,12 @@ enum SLAPillarConnectionMode {
|
||||
slapcmDynamic
|
||||
};
|
||||
|
||||
// ys_FIXME ! may be, it's not a best place
|
||||
// Additional Codes which can be set by user using DoubleSlider
|
||||
static const std::string ColorChangeCode = "M600";
|
||||
static const std::string PausePrintCode = "M601";
|
||||
static const std::string ExtruderChangeCode = "tool_change";
|
||||
|
||||
template<> inline const t_config_enum_values& ConfigOptionEnum<PrinterTechnology>::get_enum_values() {
|
||||
static t_config_enum_values keys_map;
|
||||
if (keys_map.empty()) {
|
||||
|
@ -906,7 +906,7 @@ void GLCanvas3D::LegendTexture::fill_color_print_legend_items( const GLCanvas3D
|
||||
std::vector<double> print_zs = canvas.get_current_print_zs(true);
|
||||
for (auto custom_code : custom_gcode_per_height)
|
||||
{
|
||||
if (custom_code.gcode != "M600")
|
||||
if (custom_code.gcode != ColorChangeCode)
|
||||
continue;
|
||||
auto lower_b = std::lower_bound(print_zs.begin(), print_zs.end(), custom_code.height - DoubleSlider::epsilon());
|
||||
|
||||
@ -978,7 +978,7 @@ void GLCanvas3D::LegendTexture::fill_color_print_legend_items( const GLCanvas3D
|
||||
|
||||
int cnt = custom_gcode_per_height.size();
|
||||
for (int i = cnt-1; i >= 0; --i)
|
||||
if (custom_gcode_per_height[i].gcode == "M600") {
|
||||
if (custom_gcode_per_height[i].gcode == ColorChangeCode) {
|
||||
::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + color_in_pos), 4 * sizeof(float));
|
||||
color_pos += 4;
|
||||
color_in_pos -= 4;
|
||||
@ -4842,14 +4842,15 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
||||
{
|
||||
const std::string& code = it->gcode;
|
||||
// pause print or custom Gcode
|
||||
if (code == "M601" || (code != "M600" && code != "tool_change"))
|
||||
if (code == PausePrintCode ||
|
||||
(code != ColorChangeCode && code != ExtruderChangeCode))
|
||||
return number_tools()-1; // last color item is a gray color for pause print or custom G-code
|
||||
|
||||
// change tool (extruder)
|
||||
if (code == "tool_change")
|
||||
if (code == ExtruderChangeCode)
|
||||
return get_color_idx_for_tool_change(it, extruder);
|
||||
// change color for current extruder
|
||||
if (code == "M600") {
|
||||
if (code == ColorChangeCode) {
|
||||
int color_idx = get_color_idx_for_color_change(it, extruder);
|
||||
if (color_idx >= 0)
|
||||
return color_idx;
|
||||
@ -4862,13 +4863,13 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
||||
{
|
||||
--it;
|
||||
// change color for current extruder
|
||||
if (it->gcode == "M600") {
|
||||
if (it->gcode == ColorChangeCode) {
|
||||
int color_idx = get_color_idx_for_color_change(it, extruder);
|
||||
if (color_idx >= 0)
|
||||
return color_idx;
|
||||
}
|
||||
// change tool (extruder)
|
||||
if (it->gcode == "tool_change")
|
||||
if (it->gcode == ExtruderChangeCode)
|
||||
return get_color_idx_for_tool_change(it, extruder);
|
||||
}
|
||||
|
||||
@ -4881,7 +4882,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
||||
int shift = 0;
|
||||
while (it != color_print_values->begin()) {
|
||||
--it;
|
||||
if (it->gcode == "M600")
|
||||
if (it->gcode == ColorChangeCode)
|
||||
shift++;
|
||||
}
|
||||
return extruders_cnt + shift;
|
||||
@ -4896,7 +4897,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
||||
auto it_n = it;
|
||||
while (it_n != color_print_values->begin()) {
|
||||
--it_n;
|
||||
if (it_n->gcode == "M600" && it_n->extruder == current_extruder)
|
||||
if (it_n->gcode == ColorChangeCode && it_n->extruder == current_extruder)
|
||||
return get_m600_color_idx(it_n);
|
||||
}
|
||||
|
||||
@ -4912,7 +4913,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
||||
bool is_tool_change = false;
|
||||
while (it_n != color_print_values->begin()) {
|
||||
--it_n;
|
||||
if (it_n->gcode == "tool_change") {
|
||||
if (it_n->gcode == ExtruderChangeCode) {
|
||||
is_tool_change = true;
|
||||
if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == extruder))
|
||||
return get_m600_color_idx(it);
|
||||
|
@ -893,7 +893,7 @@ void Preview::load_print_as_fff(bool keep_z_range)
|
||||
/* colors = wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||
|
||||
for (const Model::CustomGCode& code : color_print_values)
|
||||
if (code.gcode == "M600")
|
||||
if (code.gcode == ColorChangeCode)
|
||||
colors.push_back(code.color);*/
|
||||
colors = wxGetApp().plater()->get_colors_for_color_print();
|
||||
colors.push_back("#808080"); // gray color for pause print or custom G-code
|
||||
|
@ -5000,7 +5000,7 @@ std::vector<std::string> Plater::get_colors_for_color_print() const
|
||||
std::vector<std::string> colors = get_extruder_colors_from_plater_config();
|
||||
|
||||
for (const Model::CustomGCode& code : p->model.custom_gcode_per_height)
|
||||
if (code.gcode == "M600")
|
||||
if (code.gcode == ColorChangeCode)
|
||||
colors.push_back(code.color);
|
||||
|
||||
return colors;
|
||||
|
@ -2854,10 +2854,10 @@ void DoubleSlider::draw_ticks(wxDC& dc)
|
||||
is_horizontal() ? dc.DrawLine(pos, mid+14, pos, mid+9) :
|
||||
dc.DrawLine(mid + 14, pos/* - 1*/, mid + 9, pos/* - 1*/);
|
||||
|
||||
// Draw icon for "Pause print" or "Extruder change"
|
||||
if (tick.gcode != "M600" && tick.gcode != "tool_change")
|
||||
// Draw icon for "Pause print" or "Custom Gcode"
|
||||
if (tick.gcode != Slic3r::ColorChangeCode && tick.gcode != Slic3r::ExtruderChangeCode)
|
||||
{
|
||||
wxBitmap icon = create_scaled_bitmap(nullptr, tick.gcode == "M601" ? "pause_add.png" : "add_gcode");
|
||||
wxBitmap icon = create_scaled_bitmap(nullptr, tick.gcode == Slic3r::PausePrintCode ? "pause_add.png" : "add_gcode");
|
||||
|
||||
wxCoord x_draw, y_draw;
|
||||
is_horizontal() ? x_draw = pos - 0.5 * m_tick_icon_dim : y_draw = pos - 0.5 * m_tick_icon_dim;
|
||||
@ -2943,8 +2943,8 @@ void DoubleSlider::draw_colored_band(wxDC& dc)
|
||||
size_t i = 1;
|
||||
for (auto tick : m_ticks_)
|
||||
{
|
||||
if ( (m_state == msSingleExtruder && tick.gcode != "M600") ||
|
||||
(m_state == msMultiExtruderWholePrint && tick.gcode != "tool_change") )
|
||||
if ( (m_state == msSingleExtruder && tick.gcode != Slic3r::ColorChangeCode) ||
|
||||
(m_state == msMultiExtruderWholePrint && tick.gcode != Slic3r::ExtruderChangeCode) )
|
||||
continue;
|
||||
|
||||
const wxCoord pos = get_position_from_value(tick.tick);
|
||||
@ -3199,13 +3199,13 @@ wxString DoubleSlider::get_tooltip(IconFocus icon_focus)
|
||||
_(L("For add color change use left mouse button click")) :
|
||||
_(L("For add change extruder use left mouse button click"))) + "\n" +
|
||||
_(L("For add another code use right mouse button click")) :
|
||||
// tick_code_it->gcode == "M600" ? _(L("Delete color change")) :
|
||||
tick_code_it->gcode == "M600" ? ( m_state == msSingleExtruder ? //_(L("Delete color change")) :
|
||||
// tick_code_it->gcode == Slic3r::ColorChangeCode ? _(L("Delete color change")) :
|
||||
tick_code_it->gcode == Slic3r::ColorChangeCode ? ( m_state == msSingleExtruder ? //_(L("Delete color change")) :
|
||||
_(L("For Delete color change use left mouse button click\n"
|
||||
"For Delete color change or Edit color use right mouse button click")) :
|
||||
from_u8((boost::format(_utf8(L("Delete color change for Extruder %1%"))) % tick_code_it->extruder).str()) ):
|
||||
tick_code_it->gcode == "M601" ? _(L("Delete pause")) :
|
||||
tick_code_it->gcode == "tool_change" ? //( m_state == msSingleExtruder ? _(L("Delete color change")) :
|
||||
tick_code_it->gcode == Slic3r::PausePrintCode ? _(L("Delete pause")) :
|
||||
tick_code_it->gcode == Slic3r::ExtruderChangeCode ? //( m_state == msSingleExtruder ? _(L("Delete color change")) :
|
||||
from_u8((boost::format(_utf8(L("Delete extruder change to \"%1%\""))) % tick_code_it->extruder).str()) /*) */:
|
||||
from_u8((boost::format(_utf8(L("Delete \"%1%\" code"))) % tick_code_it->gcode).str());
|
||||
}
|
||||
@ -3286,9 +3286,9 @@ void DoubleSlider::OnLeftUp(wxMouseEvent& event)
|
||||
|
||||
for (int i = 1; i <= extruders_cnt; i++)
|
||||
append_menu_item(add_color_change_menu, wxID_ANY, wxString::Format(_(L("Extruder %d")), i), "",
|
||||
[this, i](wxCommandEvent&) { add_code("M600", i); }, "", &menu);
|
||||
[this, i](wxCommandEvent&) { add_code(Slic3r::ColorChangeCode, i); }, "", &menu);
|
||||
|
||||
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % "M600").str());
|
||||
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % Slic3r::ColorChangeCode).str());
|
||||
wxMenuItem* add_color_change_menu_item = menu.AppendSubMenu(add_color_change_menu, menu_name, "");
|
||||
add_color_change_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "colorchange_add_off.png"));
|
||||
*/
|
||||
@ -3311,7 +3311,7 @@ void DoubleSlider::OnLeftUp(wxMouseEvent& event)
|
||||
Slic3r::GUI::wxGetApp().plater()->PopupMenu(&menu);
|
||||
}
|
||||
else
|
||||
add_code("M600");
|
||||
add_code(Slic3r::ColorChangeCode);
|
||||
|
||||
m_show_context_menu = false;
|
||||
}
|
||||
@ -3411,7 +3411,7 @@ void DoubleSlider::action_tick(const TicksAction action)
|
||||
return;
|
||||
m_suppress_add_code = true;
|
||||
if (m_state != msMultiExtruderWholePrint)
|
||||
add_code("M600");
|
||||
add_code(Slic3r::ColorChangeCode);
|
||||
m_suppress_add_code = false;
|
||||
return;
|
||||
}
|
||||
@ -3506,7 +3506,7 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
|
||||
m_show_context_menu = true;
|
||||
return;
|
||||
}
|
||||
if (it->gcode == "M600")
|
||||
if (it->gcode == Slic3r::ColorChangeCode)
|
||||
{
|
||||
// show "Edit color" or "Delete color change" menu on OnRightUp()
|
||||
m_show_edit_color_menu = true;
|
||||
@ -3524,7 +3524,7 @@ void DoubleSlider::OnRightDown(wxMouseEvent& event)
|
||||
m_lower_value = m_higher_value;
|
||||
|
||||
// set slider to "one layer" mode
|
||||
m_is_right_down = m_is_one_layer = true;
|
||||
m_is_right_down = m_is_one_layer = true;
|
||||
|
||||
Refresh();
|
||||
Update();
|
||||
@ -3539,7 +3539,7 @@ int DoubleSlider::get_extruder_for_tick(int tick)
|
||||
auto it = m_ticks_.lower_bound(tick);
|
||||
while (it != m_ticks_.begin()) {
|
||||
--it;
|
||||
if(it->gcode == "tool_change")
|
||||
if(it->gcode == Slic3r::ExtruderChangeCode)
|
||||
return it->extruder;
|
||||
}
|
||||
|
||||
@ -3575,24 +3575,24 @@ void DoubleSlider::OnRightUp(wxMouseEvent& event)
|
||||
if (i==0) // don't use M600 for default extruder, if multimaterial print is selected
|
||||
continue;
|
||||
append_menu_item(add_color_change_menu, wxID_ANY, item_name, "",
|
||||
[this, i](wxCommandEvent&) { add_code("M600", i); }, "", &menu);
|
||||
[this, i](wxCommandEvent&) { add_code(Slic3r::ColorChangeCode, i); }, "", &menu);
|
||||
}
|
||||
|
||||
wxMenuItem* change_extruder_menu_item = menu.AppendSubMenu(change_extruder_menu, _(L("Change extruder")), _(L("Use another extruder")));
|
||||
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "change_extruder"));
|
||||
|
||||
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % "M600").str());
|
||||
const wxString menu_name = from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % Slic3r::ColorChangeCode).str());
|
||||
wxMenuItem* add_color_change_menu_item = menu.AppendSubMenu(add_color_change_menu, menu_name, "");
|
||||
add_color_change_menu_item->SetBitmap(create_scaled_bitmap(nullptr, "colorchange_add_off.png"));
|
||||
}
|
||||
}
|
||||
else
|
||||
append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
|
||||
[this](wxCommandEvent&) { add_code("M600"); }, "colorchange_add_off.png", &menu);
|
||||
[this](wxCommandEvent&) { add_code(Slic3r::ColorChangeCode); }, "colorchange_add_off.png", &menu);
|
||||
|
||||
if (m_state != msMultiExtruder)
|
||||
append_menu_item(&menu, wxID_ANY, _(L("Add pause print")) + " (M601)", "",
|
||||
[this](wxCommandEvent&) { add_code("M601"); }, "pause_add.png", &menu);
|
||||
[this](wxCommandEvent&) { add_code(Slic3r::PausePrintCode); }, "pause_add.png", &menu);
|
||||
|
||||
append_menu_item(&menu, wxID_ANY, _(L("Add custom G-code")), "",
|
||||
[this](wxCommandEvent&) { add_code(""); }, "add_gcode", &menu);
|
||||
@ -3645,7 +3645,7 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
|
||||
if (it == m_ticks_.end())
|
||||
{
|
||||
std::string color = "";
|
||||
if (code == "M600")
|
||||
if (code == Slic3r::ColorChangeCode)
|
||||
{
|
||||
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||
|
||||
@ -3653,7 +3653,7 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
|
||||
auto before_tick_it = std::lower_bound(m_ticks_.begin(), m_ticks_.end(), tick);
|
||||
while (before_tick_it != m_ticks_.begin()) {
|
||||
--before_tick_it;
|
||||
if (before_tick_it->gcode == "M600") {
|
||||
if (before_tick_it->gcode == Slic3r::ColorChangeCode) {
|
||||
color = before_tick_it->color;
|
||||
break;
|
||||
}
|
||||
@ -3686,7 +3686,7 @@ void DoubleSlider::add_code(std::string code, int selected_extruder/* = -1*/)
|
||||
|
||||
int extruder = 1;
|
||||
if (m_state == msMultiExtruderWholePrint) {
|
||||
if (code == "M600" && selected_extruder >= 0)
|
||||
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);
|
||||
@ -3730,7 +3730,7 @@ void DoubleSlider::change_extruder(int extruder)
|
||||
// if on this Y doesn't exist tick
|
||||
if (m_ticks_.find(tick) == m_ticks_.end())
|
||||
{
|
||||
m_ticks_.insert(TICK_CODE(tick, "tool_change", extruder, extruder == 0 ? "" : colors[extruder-1]));
|
||||
m_ticks_.insert(TICK_CODE(tick, Slic3r::ExtruderChangeCode, extruder, extruder == 0 ? "" : colors[extruder-1]));
|
||||
|
||||
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
|
||||
Refresh();
|
||||
@ -3747,7 +3747,7 @@ void DoubleSlider::edit_extruder_sequence()
|
||||
m_extruders_sequence = dlg.GetValue();
|
||||
|
||||
m_ticks_.erase(std::remove_if(m_ticks_.begin(), m_ticks_.end(),
|
||||
[](TICK_CODE tick) { return tick.gcode == "tool_change"; }), m_ticks_.end());
|
||||
[](TICK_CODE tick) { return tick.gcode == Slic3r::ExtruderChangeCode; }), m_ticks_.end());
|
||||
|
||||
int tick = 0;
|
||||
double value = 0.0;
|
||||
@ -3759,7 +3759,7 @@ void DoubleSlider::edit_extruder_sequence()
|
||||
while (tick <= m_max_value)
|
||||
{
|
||||
int cur_extruder = m_extruders_sequence.extruders[extruder];
|
||||
m_ticks_.insert(TICK_CODE(tick, "tool_change", cur_extruder + 1, colors[cur_extruder]));
|
||||
m_ticks_.insert(TICK_CODE(tick, Slic3r::ExtruderChangeCode, cur_extruder + 1, colors[cur_extruder]));
|
||||
|
||||
extruder++;
|
||||
if (extruder == extr_cnt)
|
||||
|
@ -963,11 +963,11 @@ private:
|
||||
|
||||
struct TICK_CODE
|
||||
{
|
||||
TICK_CODE(int tick):tick(tick), gcode("M600"), extruder(0), color("") {}
|
||||
TICK_CODE(int tick):tick(tick), gcode(Slic3r::ColorChangeCode), extruder(0), color("") {}
|
||||
TICK_CODE(int tick, const std::string& code) :
|
||||
tick(tick), gcode(code), extruder(0) {}
|
||||
TICK_CODE(int tick, int extruder) :
|
||||
tick(tick), gcode("M600"), extruder(extruder) {}
|
||||
tick(tick), gcode(Slic3r::ColorChangeCode), extruder(extruder) {}
|
||||
TICK_CODE(int tick, const std::string& code, int extruder, const std::string& color) :
|
||||
tick(tick), gcode(code), extruder(extruder), color(color) {}
|
||||
|
||||
@ -976,13 +976,7 @@ private:
|
||||
TICK_CODE operator=(const TICK_CODE& other) const {
|
||||
TICK_CODE ret_val(other.tick, other.gcode, other.extruder, other.color);
|
||||
return ret_val;
|
||||
}/*
|
||||
TICK_CODE& operator=(const TICK_CODE& other) {
|
||||
this->tick = other.tick;
|
||||
this->gcode = other.gcode;
|
||||
this->extruder = other.extruder;
|
||||
return *this;
|
||||
}*/
|
||||
}
|
||||
|
||||
int tick;
|
||||
std::string gcode;
|
||||
|
Loading…
Reference in New Issue
Block a user