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) {
// 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;
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)
extruder_printing_above[i] = true;
// 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())
// Custom G-codes were processed.
break;

View file

@ -13,7 +13,7 @@ namespace Slic3r {
// Additional Codes which can be set by user using DoubleSlider
static constexpr char ColorChangeCode[] = "M600";
static constexpr char PausePrintCode[] = "M601";
static constexpr char ExtruderChangeCode[] = "tool_change";
static constexpr char ToolChangeCode[] = "tool_change";
class GCodeWriter {
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;
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
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;
std::string gcode;
int extruder; // 0 - "gcode" will be applied for whole print
// else - "gcode" will be applied only for "extruder" print
int extruder; // Informative value for ColorChangeCode and ToolChangeCode
// "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,
// 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;
}
// 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)
{
auto it_a = va.begin();
auto it_b = vb.begin();
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.
++ it_a;
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.
++ it_b;
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())
// va or vb contains more Tool Changes than the other.
return true;
assert(it_a->gcode == ExtruderChangeCode);
assert(it_b->gcode == ExtruderChangeCode);
assert(it_a->gcode == ToolChangeCode);
assert(it_b->gcode == ToolChangeCode);
if (*it_a != *it_b)
// The two Tool Changes differ.
return true;