From 66814d687e3a0d2a56b6b0614241bff246d32667 Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Tue, 10 Dec 2024 16:19:27 +0800 Subject: [PATCH] FIX: get wrong value in retract params 1.Should get value by filament id instead of extruder id 2.Fix many other issues caused by incorrect usage jira:NONE Signed-off-by: xun.zhang Change-Id: I3278d7de0f8976a97c9e5ccef80bba4a58553f5a (cherry picked from commit 30c51dd1171fc16ba778308745fab2eb246aedd0) (cherry picked from commit e9027478f8948352d99d33519994b044ca18a65a) --- src/libslic3r/Extruder.cpp | 16 ++++++++-------- src/libslic3r/GCode.cpp | 36 +++++++++++++++++------------------ src/libslic3r/GCodeWriter.cpp | 3 ++- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/libslic3r/Extruder.cpp b/src/libslic3r/Extruder.cpp index 85f78dd31f..4a58c0590c 100644 --- a/src/libslic3r/Extruder.cpp +++ b/src/libslic3r/Extruder.cpp @@ -168,22 +168,22 @@ double Extruder::filament_flow_ratio() const // Return a "retract_before_wipe" percentage as a factor clamped to <0, 1> double Extruder::retract_before_wipe() const { - return std::min(1., std::max(0., m_config->retract_before_wipe.get_at(extruder_id()) * 0.01)); + return std::min(1., std::max(0., m_config->retract_before_wipe.get_at(m_id) * 0.01)); } double Extruder::retraction_length() const { - return m_config->retraction_length.get_at(extruder_id()); + return m_config->retraction_length.get_at(m_id); } double Extruder::retract_lift() const { - return m_config->z_hop.get_at(extruder_id()); + return m_config->z_hop.get_at(m_id); } int Extruder::retract_speed() const { - return int(floor(m_config->retraction_speed.get_at(extruder_id())+0.5)); + return int(floor(m_config->retraction_speed.get_at(m_id)+0.5)); } bool Extruder::use_firmware_retraction() const @@ -193,23 +193,23 @@ bool Extruder::use_firmware_retraction() const int Extruder::deretract_speed() const { - int speed = int(floor(m_config->deretraction_speed.get_at(extruder_id())+0.5)); + int speed = int(floor(m_config->deretraction_speed.get_at(m_id)+0.5)); return (speed > 0) ? speed : this->retract_speed(); } double Extruder::retract_restart_extra() const { - return m_config->retract_restart_extra.get_at(extruder_id()); + return m_config->retract_restart_extra.get_at(m_id); } double Extruder::retract_length_toolchange() const { - return m_config->retract_length_toolchange.get_at(extruder_id()); + return m_config->retract_length_toolchange.get_at(m_id); } double Extruder::retract_restart_extra_toolchange() const { - return m_config->retract_restart_extra_toolchange.get_at(extruder_id()); + return m_config->retract_restart_extra_toolchange.get_at(m_id); } double Extruder::travel_slope() const diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index a8a00c00d8..caf5d93d74 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -424,7 +424,7 @@ static std::vector get_path_of_change_filament(const Print& print) amount of retraction. In other words, how far do we move in XY at wipe_speed for the time needed to consume retraction_length at retraction_speed? */ // BBS - double wipe_dist = scale_(gcodegen.config().wipe_distance.get_at(gcodegen.writer().filament() ->extruder_id())); + double wipe_dist = scale_(gcodegen.config().wipe_distance.get_at(gcodegen.writer().filament()->id())); /* Take the stored wipe path and replace first point with the current actual position (they might be different, for example, in case of loop clipping). */ @@ -1636,10 +1636,10 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu m_processor.result().support_traditional_timelapse = m_support_traditional_timelapse; bool activate_long_retraction_when_cut = false; - for (const auto& extruder : m_writer.extruders()) + for (const auto& filament : m_writer.extruders()) activate_long_retraction_when_cut |= ( - m_config.long_retractions_when_cut.get_at(extruder.extruder_id()) - && m_config.retraction_distances_when_cut.get_at(extruder.extruder_id()) > 0 + m_config.long_retractions_when_cut.get_at(filament.id()) + && m_config.retraction_distances_when_cut.get_at(filament.id()) > 0 ); m_processor.result().long_retraction_when_cut = activate_long_retraction_when_cut; @@ -2301,8 +2301,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato this->placeholder_parser().set("initial_no_support_extruder", initial_non_support_extruder_id); this->placeholder_parser().set("current_extruder", initial_extruder_id); //Orca: set the key for compatibilty - this->placeholder_parser().set("retraction_distance_when_cut", m_config.retraction_distances_when_cut.get_at(extruder_id)); - this->placeholder_parser().set("long_retraction_when_cut", m_config.long_retractions_when_cut.get_at(extruder_id)); + this->placeholder_parser().set("retraction_distance_when_cut", m_config.retraction_distances_when_cut.get_at(initial_extruder_id)); + this->placeholder_parser().set("long_retraction_when_cut", m_config.long_retractions_when_cut.get_at(initial_extruder_id)); this->placeholder_parser().set("temperature", new ConfigOptionInts(print.config().nozzle_temperature)); @@ -4758,10 +4758,10 @@ std::string GCode::change_layer(coordf_t print_z) gcode += m_writer.update_progress(++ m_layer_index, m_layer_count); //BBS coordf_t z = print_z + m_config.z_offset.value; // in unscaled coordinates - if (EXTRUDER_CONFIG(retract_when_changing_layer) && m_writer.will_move_z(z)) { - LiftType lift_type = this->to_lift_type(ZHopType(EXTRUDER_CONFIG(z_hop_types))); + if (FILAMENT_CONFIG(retract_when_changing_layer) && m_writer.will_move_z(z)) { + LiftType lift_type = this->to_lift_type(ZHopType(FILAMENT_CONFIG(z_hop_types))); //BBS: force to use SpiralLift when change layer if lift type is auto - gcode += this->retract(false, false, ZHopType(EXTRUDER_CONFIG(z_hop_types)) == ZHopType::zhtAuto ? LiftType::SpiralLift : lift_type); + gcode += this->retract(false, false, ZHopType(FILAMENT_CONFIG(z_hop_types)) == ZHopType::zhtAuto ? LiftType::SpiralLift : lift_type); } m_writer.add_object_change_labels(gcode); @@ -5027,7 +5027,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou } // BBS - if (m_wipe.enable && EXTRUDER_CONFIG(wipe)) { + if (m_wipe.enable && FILAMENT_CONFIG(wipe)) { m_wipe.path = Polyline(); for (ExtrusionPath &path : paths) { //BBS: Don't need to save duplicated point into wipe path @@ -5112,7 +5112,7 @@ std::string GCode::extrude_multi_path(ExtrusionMultiPath multipath, std::string } // BBS - if (m_wipe.enable && EXTRUDER_CONFIG(wipe)) { + if (m_wipe.enable && FILAMENT_CONFIG(wipe)) { m_wipe.path = Polyline(); for (ExtrusionPath &path : multipath.paths) { //BBS: Don't need to save duplicated point into wipe path @@ -5148,7 +5148,7 @@ std::string GCode::extrude_path(ExtrusionPath path, std::string description, dou m_multi_flow_segment_path_average_mm3_per_mm = 0; // description += ExtrusionEntity::role_to_string(path.role()); std::string gcode = this->_extrude(path, description, speed); - if (m_wipe.enable && EXTRUDER_CONFIG(wipe)) { + if (m_wipe.enable && FILAMENT_CONFIG(wipe)) { m_wipe.path = std::move(path.polyline); m_wipe.path.reverse(); } @@ -6353,7 +6353,7 @@ LiftType GCode::to_lift_type(ZHopType z_hop_types) { bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftType& lift_type) { - if (travel.length() < scale_(EXTRUDER_CONFIG(retraction_minimum_travel))) { + if (travel.length() < scale_(FILAMENT_CONFIG(retraction_minimum_travel))) { // skip retraction if the move is shorter than the configured threshold return false; } @@ -6432,11 +6432,11 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp //BBS: force to retract when leave from external perimeter for a long travel //Better way is judging whether the travel move direction is same with last extrusion move. if (is_perimeter(m_last_processor_extrusion_role) && m_last_processor_extrusion_role != erPerimeter) { - if (ZHopType(EXTRUDER_CONFIG(z_hop_types)) == ZHopType::zhtAuto) { + if (ZHopType(FILAMENT_CONFIG(z_hop_types)) == ZHopType::zhtAuto) { lift_type = is_through_overhang(clipped_travel) ? LiftType::SpiralLift : LiftType::LazyLift; } else { - lift_type = to_lift_type(ZHopType(EXTRUDER_CONFIG(z_hop_types))); + lift_type = to_lift_type(ZHopType(FILAMENT_CONFIG(z_hop_types))); } return true; } @@ -6466,11 +6466,11 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp return false; // retract if reduce_infill_retraction is disabled or doesn't apply when role is perimeter - if (ZHopType(EXTRUDER_CONFIG(z_hop_types)) == ZHopType::zhtAuto) { + if (ZHopType(FILAMENT_CONFIG(z_hop_types)) == ZHopType::zhtAuto) { lift_type = is_through_overhang(clipped_travel) ? LiftType::SpiralLift : LiftType::LazyLift; } else { - lift_type = to_lift_type(ZHopType(EXTRUDER_CONFIG(z_hop_types))); + lift_type = to_lift_type(ZHopType(FILAMENT_CONFIG(z_hop_types))); } return true; } @@ -6483,7 +6483,7 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li return gcode; // wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance) - if (EXTRUDER_CONFIG(wipe) && m_wipe.has_path() && scale_(EXTRUDER_CONFIG(wipe_distance)) > SCALED_EPSILON) { + if (FILAMENT_CONFIG(wipe) && m_wipe.has_path() && scale_(FILAMENT_CONFIG(wipe_distance)) > SCALED_EPSILON) { Wipe::RetractionValues wipeRetractions = m_wipe.calculateWipeRetractionLengths(*this, toolchange); gcode += toolchange ? m_writer.retract_for_toolchange(true,wipeRetractions.retractLengthBeforeWipe) : m_writer.retract(true, wipeRetractions.retractLengthBeforeWipe); gcode += m_wipe.wipe(*this,wipeRetractions.retractLengthDuringWipe, toolchange, is_last_retraction); diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 04d546c98f..91115c9ed2 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -862,10 +862,11 @@ std::string GCodeWriter::lift(LiftType lift_type, bool spiral_vase) double target_lift = 0; { int extruder_id = filament()->extruder_id(); + int filament_id = filament()->id(); double above = this->config.retract_lift_above.get_at(extruder_id); double below = this->config.retract_lift_below.get_at(extruder_id); if (m_pos(2) >= above && (below == 0 || m_pos(2) <= below)) - target_lift = this->config.z_hop.get_at(extruder_id); + target_lift = this->config.z_hop.get_at(filament_id); } // BBS if (m_lifted == 0 && m_to_lift == 0 && target_lift > 0) {