diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 91f8535dfd..18cfe2488e 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -9900,7 +9900,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, const std::string &path_d } // BBS: use G1 if not enable arc fitting or has no arc fitting result or in spiral_mode mode or we are doing sloped extrusion // Attention: G2 and G3 is not supported in spiral_mode mode - if (!m_config.enable_arc_fitting || path.polyline.fitting_result.empty() || m_config.spiral_mode || sloped != nullptr || path.z_contoured || this->should_disable_arc_fitting()) { + if (m_config.enable_arc_fitting.value == ArcFittingMode::Disabled || path.polyline.fitting_result.empty() || m_config.spiral_mode || sloped != nullptr || path.z_contoured || this->should_disable_arc_fitting()) { double path_length = 0.; double total_length = sloped == nullptr ? 0. : path.polyline.length() * SCALING_FACTOR; double saved_z = m_writer.get_position().z(); diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index b72e924da4..0e57c41804 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -2003,7 +2003,7 @@ WipeTower::WipeTower(const PrintConfig& config, int plate_idx, Vec3d plate_origi m_flat_ironing(config.prime_tower_flat_ironing.value), m_enable_tower_interface_features(config.enable_tower_interface_features.value), m_physical_extruder_map(config.physical_extruder_map.values), - m_enable_arc_fitting(config.enable_arc_fitting.value) + m_enable_arc_fitting(config.enable_arc_fitting.value == ArcFittingMode::Enabled) // Orca: has_filament_switcher is a device-set dynamic key, not a PrintConfig member; // it is pushed in from Print via set_has_filament_switcher() instead of read here. { diff --git a/src/libslic3r/GCode/WipeTower2.cpp b/src/libslic3r/GCode/WipeTower2.cpp index 21556e65ba..83729a72a1 100644 --- a/src/libslic3r/GCode/WipeTower2.cpp +++ b/src/libslic3r/GCode/WipeTower2.cpp @@ -1062,7 +1062,7 @@ WipeTower2::WipeTower2(const PrintConfig& config, const PrintRegionConfig& defau m_perimeter_speed(default_region_config.inner_wall_speed.get_at(get_extruder_index(config, (unsigned int)initial_tool))), m_current_tool(initial_tool), wipe_volumes(wiping_matrix), m_wipe_tower_max_purge_speed(float(config.wipe_tower_max_purge_speed)), - m_enable_arc_fitting(config.enable_arc_fitting), + m_enable_arc_fitting(config.enable_arc_fitting.value == ArcFittingMode::Enabled), m_used_fillet(config.wipe_tower_fillet_wall), m_rib_width(config.wipe_tower_rib_width), m_extra_rib_length(config.wipe_tower_extra_rib_length), diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 617fc2ce54..4eed23d7d8 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -1215,7 +1215,7 @@ std::string GCodeWriter::_spiral_travel_to_z(double z, const Vec2d &ij_offset, c : this->config.travel_speed.get_at(m_cached_extruder_idx); } - if (!this->config.enable_arc_fitting) { // Orca: if arc fitting is disabled, approximate the arc with small linear segments + if (this->config.enable_arc_fitting.value == ArcFittingMode::Disabled) { // Orca: if arc fitting is disabled, approximate the arc with small linear segments const double z_start = m_pos(2); // starting Z height const double px = m_pos(0) - m_x_offset; // take plate offset into consideration diff --git a/src/libslic3r/Layer.cpp b/src/libslic3r/Layer.cpp index 8e58a5e671..849b57e4b3 100644 --- a/src/libslic3r/Layer.cpp +++ b/src/libslic3r/Layer.cpp @@ -380,7 +380,7 @@ void Layer::simplify_support_path(ExtrusionPath * path) { const auto &print_config = this->object()->print()->config(); const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const bool enable_arc_fitting = print_config.enable_arc_fitting.value == ArcFittingMode::Enabled; const auto scaled_resolution = scaled(print_config.resolution.value); if (enable_arc_fitting && @@ -395,7 +395,7 @@ void Layer::simplify_support_multi_path(ExtrusionMultiPath* multipath) { const auto &print_config = this->object()->print()->config(); const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const bool enable_arc_fitting = print_config.enable_arc_fitting.value == ArcFittingMode::Enabled; const auto scaled_resolution = scaled(print_config.resolution.value); for (size_t i = 0; i < multipath->paths.size(); ++i) { @@ -412,7 +412,7 @@ void Layer::simplify_support_loop(ExtrusionLoop* loop) { const auto &print_config = this->object()->print()->config(); const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const bool enable_arc_fitting = print_config.enable_arc_fitting.value == ArcFittingMode::Enabled; const auto scaled_resolution = scaled(print_config.resolution.value); for (size_t i = 0; i < loop->paths.size(); ++i) { diff --git a/src/libslic3r/LayerRegion.cpp b/src/libslic3r/LayerRegion.cpp index eef3f90c87..74ef2b7494 100644 --- a/src/libslic3r/LayerRegion.cpp +++ b/src/libslic3r/LayerRegion.cpp @@ -1101,16 +1101,13 @@ void LayerRegion::simplify_entity_collection(ExtrusionEntityCollection* entity_c void LayerRegion::simplify_path(ExtrusionPath* path) { const auto &print_config = this->layer()->object()->print()->config(); - const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const ArcFittingMode arc_fitting = print_config.enable_arc_fitting.value; + const bool is_sparse_infill = path->role() == erInternalInfill; const auto scaled_resolution = scaled(print_config.resolution.value); - if (enable_arc_fitting && - !spiral_mode) { - if (path->role() == erInternalInfill) - path->simplify_by_fitting_arc(SCALED_SPARSE_INFILL_RESOLUTION); - else - path->simplify_by_fitting_arc(scaled_resolution); + if (!print_config.spiral_mode && + (arc_fitting == ArcFittingMode::Enabled || (arc_fitting == ArcFittingMode::SparseInfill && is_sparse_infill))) { + path->simplify_by_fitting_arc(is_sparse_infill ? SCALED_SPARSE_INFILL_RESOLUTION : scaled_resolution); } else { path->simplify(scaled_resolution); } @@ -1118,42 +1115,14 @@ void LayerRegion::simplify_path(ExtrusionPath* path) void LayerRegion::simplify_multi_path(ExtrusionMultiPath* multipath) { - const auto &print_config = this->layer()->object()->print()->config(); - const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; - const auto scaled_resolution = scaled(print_config.resolution.value); - - for (size_t i = 0; i < multipath->paths.size(); ++i) { - if (enable_arc_fitting && - !spiral_mode) { - if (multipath->paths[i].role() == erInternalInfill) - multipath->paths[i].simplify_by_fitting_arc(SCALED_SPARSE_INFILL_RESOLUTION); - else - multipath->paths[i].simplify_by_fitting_arc(scaled_resolution); - } else { - multipath->paths[i].simplify(scaled_resolution); - } - } + for (ExtrusionPath &path : multipath->paths) + this->simplify_path(&path); } void LayerRegion::simplify_loop(ExtrusionLoop* loop) { - const auto &print_config = this->layer()->object()->print()->config(); - const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; - const auto scaled_resolution = scaled(print_config.resolution.value); - - for (size_t i = 0; i < loop->paths.size(); ++i) { - if (enable_arc_fitting && - !spiral_mode) { - if (loop->paths[i].role() == erInternalInfill) - loop->paths[i].simplify_by_fitting_arc(SCALED_SPARSE_INFILL_RESOLUTION); - else - loop->paths[i].simplify_by_fitting_arc(scaled_resolution); - } else { - loop->paths[i].simplify(scaled_resolution); - } - } + for (ExtrusionPath &path : loop->paths) + this->simplify_path(&path); } } diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index 219b6b2551..42963a4575 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -1527,7 +1527,7 @@ void PerimeterGenerator::process_classic() process_no_bridge(all_surfaces, perimeter_spacing, ext_perimeter_width); // BBS: don't simplify too much which influence arc fitting when export gcode if arc_fitting is enabled - double surface_simplify_resolution = (print_config->enable_arc_fitting && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; + double surface_simplify_resolution = (print_config->enable_arc_fitting.value == ArcFittingMode::Enabled && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; //BBS: reorder the surface to reduce the travel time ExPolygons surface_exp; for (const Surface &surface : all_surfaces) @@ -2577,7 +2577,7 @@ void PerimeterGenerator::process_arachne() process_no_bridge(all_surfaces, perimeter_spacing, ext_perimeter_width); // BBS: don't simplify too much which influence arc fitting when export gcode if arc_fitting is enabled - double surface_simplify_resolution = (print_config->enable_arc_fitting && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; + double surface_simplify_resolution = (print_config->enable_arc_fitting.value == ArcFittingMode::Enabled && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; // ORCA: neither one-wall option has a surface to act on without the shell behind it, see // has_top_shell_layers() / has_bottom_shell_layers(). Gated here so every use below - including the // topmost and first layers - sees the same answer. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 8e1b2b028e..164bdece3b 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -252,6 +252,14 @@ static t_config_enum_values s_keys_map_PowerLossRecoveryMode { }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(PowerLossRecoveryMode) +// Orca +static t_config_enum_values s_keys_map_ArcFittingMode { + { "disabled", int(ArcFittingMode::Disabled) }, + { "enabled", int(ArcFittingMode::Enabled) }, + { "sparse_infill", int(ArcFittingMode::SparseInfill) } +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(ArcFittingMode) + static t_config_enum_values s_keys_map_CenterOfSurfacePattern{ {"each_surface", int(CenterOfSurfacePattern::Each_Surface)}, {"each_model", int(CenterOfSurfacePattern::Each_Model)}, @@ -4401,16 +4409,25 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionBool(0)); // BBS - def = this->add("enable_arc_fitting", coBool); + def = this->add("enable_arc_fitting", coEnum); def->label = L("Arc fitting"); - def->tooltip = L("Enable this to get a G-code file which has G2 and G3 moves. " - "The fitting tolerance is same as the resolution.\n\n" - "Note: For Klipper machines, this option is recommended to be disabled. Klipper does not benefit from " - "arc commands as these are split again into line segments by the firmware. This results in a reduction " - "in surface quality as line segments are converted to arcs by the slicer and then back to line segments " - "by the firmware."); + def->tooltip = L("Fit G2 and G3 arc moves to the toolpaths. Walls and surfaces are fitted within the resolution, while " + "sparse infill, supports and the wipe tower use fixed tolerances.\n" + " - Disabled: only straight G1 moves are used.\n" + " - Enabled: arcs are fitted to all toolpaths.\n" + " - Sparse infill only: arcs are fitted to the sparse infill only, which shortens the G-code of " + "curved infill patterns without affecting the walls and surfaces.\n\n" + "Note: For Klipper machines, Disabled is recommended. Klipper splits arcs back into line segments, " + "which lowers the surface quality and can increase the print time."); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("disabled"); + def->enum_values.push_back("enabled"); + def->enum_values.push_back("sparse_infill"); + def->enum_labels.push_back(L("Disabled")); + def->enum_labels.push_back(L("Enabled")); + def->enum_labels.push_back(L("Sparse infill only")); def->mode = comAdvanced; - def->set_default_value(new ConfigOptionBool(0)); + def->set_default_value(new ConfigOptionEnum(ArcFittingMode::Disabled)); // BBS def = this->add("gcode_add_line_number", coBool); def->label = L("Add line number"); @@ -9833,6 +9850,13 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va value = "disable"; } } + else if (opt_key == "enable_arc_fitting") { + if (value == "1" || boost::iequals(value, "true")) { + value = "enabled"; + } else if (value == "0" || boost::iequals(value, "false")) { + value = "disabled"; + } + } else if(opt_key == "ensure_vertical_shell_thickness") { if(value == "1") { value = "ensure_all"; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 0ebeabb3eb..e712c4565f 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -234,6 +234,13 @@ enum class PowerLossRecoveryMode { Disable, }; +// Orca +enum class ArcFittingMode { + Disabled, + Enabled, + SparseInfill, +}; + // BBS enum class WallSequence { InnerOuter, @@ -823,6 +830,7 @@ CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(WipeTowerWallType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PerimeterGeneratorType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ToolChangeOrderingType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PowerLossRecoveryMode) +CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ArcFittingMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SurfaceFillOrder) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AdaptiveInfillMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AdaptiveInfillGradient) @@ -1693,7 +1701,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionString, printing_by_object_gcode)) ((ConfigOptionFloats, deretraction_speed)) //BBS - ((ConfigOptionBool, enable_arc_fitting)) + ((ConfigOptionEnum, enable_arc_fitting)) ((ConfigOptionString, machine_end_gcode)) ((ConfigOptionStrings, filament_end_gcode)) ((ConfigOptionFloatsNullable, filament_flow_ratio)) diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index a03f63c737..9af9a4309f 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -807,7 +807,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, in toggle_field("enable_arc_fitting", !have_volumetric_extrusion_rate_slope && !is_belt_printer); toggle_line("max_volumetric_extrusion_rate_slope_segment_length", have_volumetric_extrusion_rate_slope); toggle_line("extrusion_rate_smoothing_external_perimeter_only", have_volumetric_extrusion_rate_slope); - if(have_volumetric_extrusion_rate_slope) config->set_key_value("enable_arc_fitting", new ConfigOptionBool(false)); + if(have_volumetric_extrusion_rate_slope) config->set_key_value("enable_arc_fitting", new ConfigOptionEnum(ArcFittingMode::Disabled)); if(have_volumetric_extrusion_rate_slope_segment_length < 0.5) { DynamicPrintConfig new_conf = *config; new_conf.set_key_value("max_volumetric_extrusion_rate_slope_segment_length", new ConfigOptionFloat(1)); diff --git a/tests/fff_print/test_cooling.cpp b/tests/fff_print/test_cooling.cpp index 1645d99a75..a1a840c745 100644 --- a/tests/fff_print/test_cooling.cpp +++ b/tests/fff_print/test_cooling.cpp @@ -40,7 +40,7 @@ TEST_CASE("Arc fitting remains active with overhang fan control", "[Cooling][Reg { DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); config.set_deserialize_strict({ - { "enable_arc_fitting", true }, + { "enable_arc_fitting", "enabled" }, { "enable_overhang_bridge_fan", true }, { "enable_overhang_speed", true }, { "initial_layer_print_height", 0.2 }, @@ -99,7 +99,7 @@ TEST_CASE("Overhang fan transitions do not depend on overhang speed", "[Cooling] DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); config.set_deserialize_strict({ { "bridge_speed", 2.0 }, - { "enable_arc_fitting", false }, + { "enable_arc_fitting", "disabled" }, { "enable_overhang_bridge_fan", true }, { "enable_overhang_speed", false }, { "initial_layer_print_height", 0.3 }, diff --git a/tests/fff_print/test_gcode.cpp b/tests/fff_print/test_gcode.cpp index cb707ae3d4..1fbb84d08c 100644 --- a/tests/fff_print/test_gcode.cpp +++ b/tests/fff_print/test_gcode.cpp @@ -16,9 +16,12 @@ #include "libslic3r/TriangleMesh.hpp" #include "libslic3r/Point.hpp" +#include "libslic3r/libslic3r.h" #include #include #include +#include +#include #include #include #include @@ -213,6 +216,40 @@ TEST_CASE("Object label comments number each object and copy with or without exc } } +TEST_CASE("Sparse infill only arc fitting emits arcs in the sparse infill alone", "[GCode]") +{ + const auto arcs_per_type = [](const char *arc_fitting) { + // 360 facets keep the walls and the concentric infill within the resolution of a circle, so both fit arcs. + const std::string gcode = Test::slice({ make_cylinder(25.0, 10.0, 2.0 * PI / 360.0) }, { + { "enable_arc_fitting", arc_fitting }, + { "sparse_infill_pattern", "concentric" }, + { "sparse_infill_density", "20%" }, + { "z_hop", "0" }, + }); + std::map arcs; + std::istringstream input(gcode); + std::string line, type; + while (std::getline(input, line)) { + if (line.rfind(";TYPE:", 0) == 0) + type = line.substr(6); + else if (line.rfind("G2 ", 0) == 0 || line.rfind("G3 ", 0) == 0) + ++arcs[type]; + } + return arcs; + }; + + CHECK(arcs_per_type("enabled").count("Outer wall") == 1); + + const std::map sparse_only = arcs_per_type("sparse_infill"); + CHECK(sparse_only.count("Sparse infill") == 1); + for (const auto &[type, count] : sparse_only) { + INFO(type << ": " << count << " arcs"); + CHECK(type == "Sparse infill"); + } + + CHECK(arcs_per_type("disabled").empty()); +} + TEST_CASE("An exported G-code's settings load back as the settings it was sliced with", "[GCode]") { // Two filaments, so the config block carries the flush matrix already multiplied by flush_multiplier. diff --git a/tests/libslic3r/test_config.cpp b/tests/libslic3r/test_config.cpp index b1add2b3c5..705da9d36a 100644 --- a/tests/libslic3r/test_config.cpp +++ b/tests/libslic3r/test_config.cpp @@ -1507,6 +1507,21 @@ TEST_CASE("min_object_distance yields no floor when an FFF config lacks the opti } } +TEST_CASE("handle_legacy maps the boolean arc fitting values to modes", "[Config]") { + const auto [value, mode] = GENERATE(table({ + { "0", ArcFittingMode::Disabled }, + { "false", ArcFittingMode::Disabled }, + { "1", ArcFittingMode::Enabled }, + { "true", ArcFittingMode::Enabled }, + { "sparse_infill", ArcFittingMode::SparseInfill }, + })); + INFO(value); + ConfigSubstitutionContext ctxt(ForwardCompatibilitySubstitutionRule::Disable); + DynamicPrintConfig config; + config.set_deserialize("enable_arc_fitting", value, ctxt); + CHECK(config.opt_enum("enable_arc_fitting") == mode); +} + TEST_CASE("handle_legacy migrates the adaptive TPMS keys", "[Config]") { ConfigSubstitutionContext ctxt(ForwardCompatibilitySubstitutionRule::Enable); DynamicPrintConfig config;