From aaa2e440347dff0683bd7479df1b756a33c48520 Mon Sep 17 00:00:00 2001 From: supermerill Date: Thu, 29 Oct 2020 20:09:44 +0100 Subject: merge @paukstelis M486 pull request & improving label object position. --- src/libslic3r/GCode.cpp | 86 ++++++++++++++++++++++++++++++++++++++----- src/libslic3r/GCode.hpp | 5 +++ src/libslic3r/PrintConfig.cpp | 2 +- 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index e4d569cb4..73294d4a1 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -327,6 +327,12 @@ std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::T std::string tcr_rotated_gcode = post_process_wipe_tower_moves(tcr, wipe_tower_offset, wipe_tower_rotation); + //if needed, write the gcode_label_objects_end then priming tower + if (!gcodegen.m_gcode_label_objects_end.empty()) { + gcode += gcodegen.m_gcode_label_objects_end; + gcodegen.m_gcode_label_objects_end = ""; + } + if (!tcr.priming) { // Move over the wipe tower. // Retract for a tool change, using the toolchange retract value and setting the priming extra length. @@ -1323,6 +1329,7 @@ void GCode::_do_export(Print &print, FILE *file) _write_format(file, "\n"); } BoundingBoxf3 global_bounding_box; + size_t nb_items = 0; for (PrintObject *print_object : print.objects()) { this->m_ordered_objects.push_back(print_object); unsigned int copy_id = 0; @@ -1348,8 +1355,13 @@ void GCode::_do_export(Print &print, FILE *file) ); } copy_id++; + nb_items++; } } + if (this->config().gcode_label_objects && print.config().gcode_flavor.value == gcfMarlin) { + _write(file, "; Total objects to print: " + std::to_string(nb_items) + "\n"); + _write(file, "M486 T" + std::to_string(nb_items) + "\n"); + } if (this->config().gcode_label_objects) { _write_format(file, "; plater:{\"center\":[%f,%f,%f],\"boundingbox_center\":[%f,%f,%f],\"boundingbox_size\":[%f,%f,%f]}\n", global_bounding_box.center().x(), global_bounding_box.center().y(), 0., @@ -1668,6 +1680,12 @@ void GCode::_do_export(Print &print, FILE *file) // Write end commands to file. _write(file, this->retract()); + //if needed, write the gcode_label_objects_end + { + std::string gcode; + _add_object_change_labels(gcode); + _write(file, gcode); + } _write(file, m_writer.set_fan(false)); if (m_enable_analyzer) @@ -2503,7 +2521,7 @@ void GCode::process_layer( path.mm3_per_mm = mm3_per_mm; } //FIXME using the support_material_speed of the 1st object printed. - gcode += this->extrude_loop(loop, "skirt", m_config.support_material_speed.value); + gcode += this->extrude_loop(loop, "", m_config.support_material_speed.value); } m_avoid_crossing_perimeters.use_external_mp = false; // Allow a straight travel move to the first object point if this is the first layer (but don't in next layers). @@ -2534,7 +2552,7 @@ void GCode::process_layer( this->set_origin(unscale(print_object->instances()[single_object_instance_idx].shift)); if (this->m_layer != nullptr && this->m_layer->id() < m_config.skirt_height) { for (const ExtrusionEntity *ee : print_object->skirt().entities) - gcode += this->extrude_entity(*ee, "skirt", m_config.support_material_speed.value); + gcode += this->extrude_entity(*ee, "", m_config.support_material_speed.value); } } //extrude object-only brim @@ -2573,10 +2591,26 @@ void GCode::process_layer( if (m_config.avoid_crossing_perimeters) m_avoid_crossing_perimeters.init_layer_mp(union_ex(m_layer->lslices, true)); - if (this->config().gcode_label_objects) - gcode += std::string("; printing object ") + instance_to_print.print_object.model_object()->name - + " id:" + std::to_string(std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), &instance_to_print.print_object) - this->m_ordered_objects.begin()) + //print object label to help the printer firmware know where it is (for removing the objects) + if (this->config().gcode_label_objects) { + m_gcode_label_objects_start = std::string("; printing object ") + instance_to_print.print_object.model_object()->name + + " id:" + std::to_string(std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), &instance_to_print.print_object) - this->m_ordered_objects.begin()) + + " copy " + std::to_string(instance_to_print.instance_id) + "\n"; + gcode += std::string("; INIT printing object ") + instance_to_print.print_object.model_object()->name + + " id:" + std::to_string(std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), &instance_to_print.print_object) - this->m_ordered_objects.begin()) + " copy " + std::to_string(instance_to_print.instance_id) + "\n"; + if (print.config().gcode_flavor.value == gcfMarlin) { + size_t instance_plater_id = 0; + //get index of the current copy in the whole itemset; + for (const PrintObject * obj : this->m_ordered_objects) + if (obj == &instance_to_print.print_object) + break; + else + instance_plater_id += obj->instances().size(); + instance_plater_id += instance_to_print.instance_id; + m_gcode_label_objects_start += std::string("M486 S") + std::to_string(instance_plater_id) + "\n"; + } + } //if first layer, ask for a bigger lift for travel to object, to be on the safe side set_extra_lift(layer, print, m_writer, extruder_id); // When starting a new object, use the external motion planner for the first travel move. @@ -2609,10 +2643,17 @@ void GCode::process_layer( gcode += this->extrude_perimeters(print, by_region_specific, lower_layer_edge_grids[instance_to_print.layer_id]); gcode += this->extrude_infill(print, by_region_specific, false); } - if (this->config().gcode_label_objects) - gcode += std::string("; stop printing object ") + instance_to_print.print_object.model_object()->name - + " id:" + std::to_string((std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), &instance_to_print.print_object) - this->m_ordered_objects.begin())) + if (this->config().gcode_label_objects) { + m_gcode_label_objects_end = std::string("; stop printing object ") + instance_to_print.print_object.model_object()->name + + " id:" + std::to_string((std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), &instance_to_print.print_object) - this->m_ordered_objects.begin())) + " copy " + std::to_string(instance_to_print.instance_id) + "\n"; + gcode += std::string("; INIT stop printing object ") + instance_to_print.print_object.model_object()->name + + " id:" + std::to_string((std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), &instance_to_print.print_object) - this->m_ordered_objects.begin())) + + " copy " + std::to_string(instance_to_print.instance_id) + "\n"; + if (print.config().gcode_flavor.value == gcfMarlin) { + m_gcode_label_objects_end += std::string("M486 S-1") + "\n"; + } + } } } } @@ -2640,6 +2681,10 @@ void GCode::process_layer( } } if (milling_ok) { + if (!m_gcode_label_objects_end.empty()) { + gcode += m_gcode_label_objects_end; + m_gcode_label_objects_end = ""; + } //switch to mill gcode += "; milling ok\n"; uint32_t current_extruder_filament = m_writer.tool()->id(); @@ -2805,6 +2850,9 @@ std::string GCode::change_layer(coordf_t print_z) if (BOOL_EXTRUDER_CONFIG(retract_layer_change) && m_writer.will_move_z(z)) gcode += this->retract(); + //if needed, write the gcode_label_objects_end then gcode_label_objects_start + _add_object_change_labels(gcode); + { std::ostringstream comment; comment << "move to next layer (" << m_layer_index << ")"; @@ -4123,6 +4171,10 @@ std::string GCode::_before_extrude(const ExtrusionPath &path, const std::string "move to first " + description + " point" ); } + + //if needed, write the gcode_label_objects_end then gcode_label_objects_start + //should be already done by travel_to, but just in case + _add_object_change_labels(gcode); // compensate retraction gcode += this->unretract(); @@ -4299,6 +4351,17 @@ std::string GCode::_after_extrude(const ExtrusionPath &path) { return gcode; } +void GCode::_add_object_change_labels(std::string &gcode) { + if (!m_gcode_label_objects_end.empty()) { + gcode += m_gcode_label_objects_end; + m_gcode_label_objects_end = ""; + } + if (!m_gcode_label_objects_start.empty()) { + gcode += m_gcode_label_objects_start; + m_gcode_label_objects_start = ""; + } +} + // This method accepts &point in print coordinates. std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string comment) { @@ -4337,7 +4400,10 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string else // Reset the wipe path when traveling, so one would not wipe along an old path. m_wipe.reset_path(); - + + //if needed, write the gcode_label_objects_end then gcode_label_objects_start + _add_object_change_labels(gcode); + // use G1 because we rely on paths being straight (G0 may make round paths) Lines lines = travel.lines(); if (! lines.empty()) { @@ -4407,7 +4473,7 @@ std::string GCode::retract(bool toolchange) || (!m_writer.tool_is_extruder() && m_writer.tool()->retract_lift() != 0) ) gcode += m_writer.lift(); - + return gcode; } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 6cf524490..ac8ec0e8b 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -402,6 +402,11 @@ private: // ordered list of object, to give them a unique id. std::vector m_ordered_objects; + // gcode for the start/end of the current object block. + // as the retraction/unretraction can be written after the start/end of the algoruihtmblock, it has to be delayed. + std::string m_gcode_label_objects_start; + std::string m_gcode_label_objects_end; + void _add_object_change_labels(std::string &gcode); // Time estimators GCodeTimeEstimator m_normal_time_estimator; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index fd1b4c389..108a85c4c 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2599,7 +2599,7 @@ void PrintConfigDef::init_fff_params() def = this->add("retract_layer_change", coBools); def->label = L("Retract on layer change"); def->category = OptionCategory::extruders; - def->tooltip = L("This flag enforces a retraction whenever a Z move is done."); + def->tooltip = L("This flag enforces a retraction whenever a Z move is done (before it)."); def->mode = comAdvanced; def->set_default_value(new ConfigOptionBools { false }); -- cgit v1.2.3