From a13152c61f67cd269a77c92cc3cbdc0608fa92c6 Mon Sep 17 00:00:00 2001 From: Vovodroid Date: Sat, 29 Jun 2024 12:33:22 +0300 Subject: [PATCH] Add travel_slope option (#5873) * Add travel_slope option * Merge branch 'main' into travel-slope-pr --- src/libslic3r/Extruder.cpp | 5 +++++ src/libslic3r/Extruder.hpp | 1 + src/libslic3r/GCode.cpp | 2 +- src/libslic3r/GCodeWriter.cpp | 7 +++---- src/libslic3r/GCodeWriter.hpp | 2 -- src/libslic3r/Preset.cpp | 2 +- src/libslic3r/Print.cpp | 3 ++- src/libslic3r/PrintConfig.cpp | 14 ++++++++++++-- src/libslic3r/PrintConfig.hpp | 1 + src/slic3r/GUI/Tab.cpp | 5 ++++- 10 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/Extruder.cpp b/src/libslic3r/Extruder.cpp index 0b5d68b68..8f4be4e04 100644 --- a/src/libslic3r/Extruder.cpp +++ b/src/libslic3r/Extruder.cpp @@ -203,4 +203,9 @@ double Extruder::retract_restart_extra_toolchange() const return m_config->retract_restart_extra_toolchange.get_at(m_id); } +double Extruder::travel_slope() const +{ + return m_config->travel_slope.get_at(m_id) * PI / 180; +} + } diff --git a/src/libslic3r/Extruder.hpp b/src/libslic3r/Extruder.hpp index 0568653e7..f04805545 100644 --- a/src/libslic3r/Extruder.hpp +++ b/src/libslic3r/Extruder.hpp @@ -67,6 +67,7 @@ public: double retract_restart_extra() const; double retract_length_toolchange() const; double retract_restart_extra_toolchange() const; + double travel_slope() const; bool use_firmware_retraction() const; diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index fc66dd7f0..c078d1a5d 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -5894,7 +5894,7 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp 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)); - float travel_len_thresh = scale_(max_z_hop / tan(GCodeWriter::slope_threshold)); + float travel_len_thresh = scale_(max_z_hop / tan(this->writer().extruder()->travel_slope())); float accum_len = 0.f; Polyline clipped_travel; diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 39fba8747..d4ebb6436 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -17,7 +17,6 @@ namespace Slic3r { bool GCodeWriter::full_gcode_comment = true; -const double GCodeWriter::slope_threshold = 3 * PI / 180; bool GCodeWriter::supports_separate_travel_acceleration(GCodeFlavor flavor) { @@ -458,7 +457,7 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co //BBS: SpiralLift if (m_to_lift_type == LiftType::SpiralLift && this->is_current_position_clear()) { //BBS: todo: check the arc move all in bed area, if not, then use lazy lift - double radius = delta(2) / (2 * PI * atan(GCodeWriter::slope_threshold)); + double radius = delta(2) / (2 * PI * atan(this->extruder()->travel_slope())); Vec2d ij_offset = radius * delta_no_z.normalized(); ij_offset = { -ij_offset(1), ij_offset(0) }; slop_move = this->_spiral_travel_to_z(target(2), ij_offset, "spiral lift Z"); @@ -466,11 +465,11 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co //BBS: LazyLift else if (m_to_lift_type == LiftType::LazyLift && this->is_current_position_clear() && - atan2(delta(2), delta_no_z.norm()) < GCodeWriter::slope_threshold) { + atan2(delta(2), delta_no_z.norm()) < this->extruder()->travel_slope()) { //BBS: check whether we can make a travel like // _____ // / to make the z list early to avoid to hit some warping place when travel is long. - Vec2d temp = delta_no_z.normalized() * delta(2) / tan(GCodeWriter::slope_threshold); + Vec2d temp = delta_no_z.normalized() * delta(2) / tan(this->extruder()->travel_slope()); Vec3d slope_top_point = Vec3d(temp(0), temp(1), delta(2)) + source; GCodeG1Formatter w0; w0.emit_xyz(slope_top_point); diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index b335faed4..8e1effcc4 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -108,8 +108,6 @@ public: bool is_current_position_clear() const { return m_is_current_pos_clear; }; //BBS: static bool full_gcode_comment; - //Radian threshold of slope for lazy lift and spiral lift; - static const double slope_threshold; //SoftFever void set_is_bbl_machine(bool bval) {m_is_bbl_printers = bval;} const bool is_bbl_printers() const {return m_is_bbl_printers;} diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 4a2db4c99..ff53665f2 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -866,7 +866,7 @@ static std::vector s_Preset_printer_options { "silent_mode", // BBS "scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time","time_cost", "machine_pause_gcode", "template_custom_gcode", - "nozzle_type", "nozzle_hrc","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types", "retract_lift_enforce","support_chamber_temp_control","support_air_filtration","printer_structure", + "nozzle_type", "nozzle_hrc","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types", "travel_slope", "retract_lift_enforce","support_chamber_temp_control","support_air_filtration","printer_structure", "best_object_pos","head_wrap_detect_zone", //SoftFever "host_type", "print_host", "printhost_apikey", "bbl_use_printhost", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 5d19c0427..43755c8ad 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -150,7 +150,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "retract_when_changing_layer", "retraction_length", "retract_length_toolchange", - "z_hop", + "z_hop", + "travel_slope", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 6b89595da..3caabccf3 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3557,6 +3557,15 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionEnumsGeneric{ ZHopType::zhtSlope }); + def = this->add("travel_slope", coFloats); + def->label = L("Traveling angle"); + def->tooltip = L("Traveling angle for Slope and Spiral Z hop type. Setting it to 90° results in Normal Lift"); + def->sidetext = L("°"); + def->mode = comAdvanced; + def->min = 1; + def->max = 90; + def->set_default_value(new ConfigOptionFloats { 3 }); + def = this->add("retract_lift_above", coFloats); def->label = L("Only lift Z above"); def->tooltip = L("If you set this to a positive value, Z lift will only take place above the specified absolute Z."); @@ -5113,7 +5122,7 @@ void PrintConfigDef::init_extruder_option_keys() // ConfigOptionFloats, ConfigOptionPercents, ConfigOptionBools, ConfigOptionStrings m_extruder_option_keys = { "nozzle_diameter", "min_layer_height", "max_layer_height", "extruder_offset", - "retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed", + "retraction_length", "z_hop", "z_hop_types", "travel_slope", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed", "retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance", "retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour", "default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut" @@ -5135,7 +5144,8 @@ void PrintConfigDef::init_extruder_option_keys() "wipe", "wipe_distance", "z_hop", - "z_hop_types" + "z_hop_types", + "travel_slope" }; assert(std::is_sorted(m_extruder_retract_keys.begin(), m_extruder_retract_keys.end())); } diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index ec2b92499..56666f3c1 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1060,6 +1060,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloats, z_hop)) // BBS ((ConfigOptionEnumsGeneric, z_hop_types)) + ((ConfigOptionFloats, travel_slope)) ((ConfigOptionFloats, retract_lift_above)) ((ConfigOptionFloats, retract_lift_below)) ((ConfigOptionEnumsGeneric, retract_lift_enforce)) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 667e61a1e..1415ad6e6 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3092,7 +3092,7 @@ void TabFilament::add_filament_overrides_page() for (const std::string opt_key : { "filament_retraction_length", "filament_z_hop", - "filament_z_hop_types", + "filament_z_hop_types", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_lift_enforce", @@ -4157,6 +4157,7 @@ if (is_marlin_flavor) optgroup->append_single_option_line("retract_restart_extra", "", extruder_idx); optgroup->append_single_option_line("z_hop", "", extruder_idx); optgroup->append_single_option_line("z_hop_types", "", extruder_idx); + optgroup->append_single_option_line("travel_slope", "", extruder_idx); optgroup->append_single_option_line("retraction_speed", "", extruder_idx); optgroup->append_single_option_line("deretraction_speed", "", extruder_idx); optgroup->append_single_option_line("retraction_minimum_travel", "", extruder_idx); @@ -4421,6 +4422,8 @@ void TabPrinter::toggle_options() toggle_option("long_retractions_when_cut", !use_firmware_retraction && m_config->opt_int("enable_long_retraction_when_cut"),i); toggle_line("retraction_distances_when_cut#0", m_config->opt_bool("long_retractions_when_cut", i)); //toggle_option("retraction_distances_when_cut", m_config->opt_bool("long_retractions_when_cut",i),i); + + toggle_option("travel_slope", m_config->opt_enum("z_hop_types", i) != ZHopType::zhtNormal, i); } if (m_active_page->title() == L("Motion ability")) {