diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 415db25a96..50219d5ff3 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -3016,8 +3016,11 @@ std::string GCode::change_layer(coordf_t print_z, bool lazy_raise) //BBS //coordf_t z = print_z + m_config.z_offset.value; // in unscaled coordinates coordf_t z = print_z; // in unscaled coordinates - if (EXTRUDER_CONFIG(retract_when_changing_layer) && m_writer.will_move_z(z)) - gcode += this->retract(); + if (EXTRUDER_CONFIG(retract_when_changing_layer) && m_writer.will_move_z(z)) { + LiftType lift_type = this->to_lift_type(m_config.z_hop_type); + //BBS: force to use SpiralLift when change layer if lift type is auto + gcode += this->retract(false, false, m_config.z_hop_type == ZHopType::zhtAuto? LiftType::SpiralLift : lift_type); + } if (!lazy_raise) { std::ostringstream comment; @@ -3728,6 +3731,22 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string return gcode; } +//BBS +LiftType GCode::to_lift_type(ZHopType z_hop_type) { + switch (z_hop_type) + { + case ZHopType::zhtNormal: + return LiftType::NormalLift; + case ZHopType::zhtSlope: + return LiftType::LazyLift; + case ZHopType::zhtSpiral: + return LiftType::SpiralLift; + default: + // if no corresponding lift type, use normal lift + return LiftType::NormalLift; + } +}; + bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftType& lift_type) { if (travel.length() < scale_(EXTRUDER_CONFIG(retraction_minimum_travel))) { @@ -3764,20 +3783,6 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp return false; }; - auto to_lift_type = [](ZHopType z_hop_type) { - if (z_hop_type == ZHopType::zhtNormal) - return LiftType::NormalLift; - - if (z_hop_type == ZHopType::zhtSlope) - return LiftType::LazyLift; - - if (z_hop_type == ZHopType::zhtSpiral) - return LiftType::SpiralLift; - - // if no corresponding lift type, use normal lift - return LiftType::NormalLift; - }; - float max_z_hop = 0.f; for (int i = 0; i < m_config.z_hop.size(); i++) max_z_hop = std::max(max_z_hop, (float)m_config.z_hop.get_at(i)); diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 0b898dd4bd..58f744a918 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -395,6 +395,8 @@ private: std::string extrude_support(const ExtrusionEntityCollection &support_fills); std::string travel_to(const Point &point, ExtrusionRole role, std::string comment); + // BBS + LiftType to_lift_type(ZHopType z_hop_type); // BBS: detect lift type in needs_retraction bool needs_retraction(const Polyline& travel, ExtrusionRole role, LiftType& lift_type); std::string retract(bool toolchange = false, bool is_last_retraction = false, LiftType lift_type = LiftType::SpiralLift);