From 8b0e3079414b3d0c874fa0048417dd0857bddfa7 Mon Sep 17 00:00:00 2001 From: SoftFever <103989404+SoftFever@users.noreply.github.com> Date: Sat, 27 May 2023 17:39:48 +0800 Subject: [PATCH] infill_anchor #500 #136 --- src/libslic3r/Fill/Fill.cpp | 9 +++-- src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 49 +++++++++++++++++++++++++++ src/libslic3r/PrintConfig.hpp | 5 ++- src/libslic3r/PrintObject.cpp | 2 ++ src/slic3r/GUI/ConfigManipulation.cpp | 6 +++- src/slic3r/GUI/GUI_Factories.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 3 ++ 8 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index 65e7d4b9d0..028ab8fba2 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -199,8 +199,13 @@ std::vector group_fills(const Layer &layer) // so that internall infill will be aligned over all layers of the current region. params.spacing = layerm.region().flow(*layer.object(), frInfill, layer.object()->config().layer_height, false).spacing(); // Anchor a sparse infill to inner perimeters with the following anchor length: - params.anchor_length = float(Fill::infill_anchor * 0.01 * params.spacing); - params.anchor_length_max = Fill::infill_anchor_max; + // Anchor a sparse infill to inner perimeters with the following anchor length: + params.anchor_length = float(region_config.infill_anchor); + if (region_config.infill_anchor.percent) + params.anchor_length = float(params.anchor_length * 0.01 * params.spacing); + params.anchor_length_max = float(region_config.infill_anchor_max); + if (region_config.infill_anchor_max.percent) + params.anchor_length_max = float(params.anchor_length_max * 0.01 * params.spacing); params.anchor_length = std::min(params.anchor_length, params.anchor_length_max); } diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 0931238298..02ff26aa56 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -756,7 +756,7 @@ static std::vector s_Preset_print_options { "bridge_density", "precise_outer_wall", "overhang_speed_classic", "bridge_acceleration", "sparse_infill_acceleration", "internal_solid_infill_acceleration", "tree_support_adaptive_layer_height", "tree_support_auto_brim", "tree_support_brim_width", "gcode_comments", "gcode_label_objects", - "initial_layer_travel_speed", "exclude_object", "slow_down_layers" + "initial_layer_travel_speed", "exclude_object", "slow_down_layers", "infill_anchor", "infill_anchor_max" }; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index f12cfcf3c3..d59bcd66c8 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1434,6 +1434,55 @@ void PrintConfigDef::init_fff_params() def->enum_labels.push_back(L("Lightning")); def->set_default_value(new ConfigOptionEnum(ipCubic)); + auto def_infill_anchor_min = def = this->add("infill_anchor", coFloatOrPercent); + def->label = L("Length of the infill anchor"); + def->category = L("Strength"); + def->tooltip = L("Connect an infill line to an internal perimeter with a short segment of an additional perimeter. " + "If expressed as percentage (example: 15%) it is calculated over infill extrusion width. Slic3r tries to connect two close infill lines to a short perimeter segment. If no such perimeter segment " + "shorter than infill_anchor_max is found, the infill line is connected to a perimeter segment at just one side " + "and the length of the perimeter segment taken is limited to this parameter, but no longer than anchor_length_max. " + "\nSet this parameter to zero to disable anchoring perimeters connected to a single infill line."); + def->sidetext = L("mm or %"); + def->ratio_over = "sparse_infill_line_width"; + def->max_literal = 1000; + def->gui_type = ConfigOptionDef::GUIType::f_enum_open; + def->enum_values.push_back("0"); + def->enum_values.push_back("1"); + def->enum_values.push_back("2"); + def->enum_values.push_back("5"); + def->enum_values.push_back("10"); + def->enum_values.push_back("1000"); + def->enum_labels.push_back(L("0 (no open anchors)")); + def->enum_labels.push_back("1 mm"); + def->enum_labels.push_back("2 mm"); + def->enum_labels.push_back("5 mm"); + def->enum_labels.push_back("10 mm"); + def->enum_labels.push_back(L("1000 (unlimited)")); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloatOrPercent(400, true)); + + def = this->add("infill_anchor_max", coFloatOrPercent); + def->label = L("Maximum length of the infill anchor"); + def->category = L("Strength"); + def->tooltip = L("Connect an infill line to an internal perimeter with a short segment of an additional perimeter. " + "If expressed as percentage (example: 15%) it is calculated over infill extrusion width. Slic3r tries to connect two close infill lines to a short perimeter segment. If no such perimeter segment " + "shorter than this parameter is found, the infill line is connected to a perimeter segment at just one side " + "and the length of the perimeter segment taken is limited to infill_anchor, but no longer than this parameter. " + "\nIf set to 0, the old algorithm for infill connection will be used, it should create the same result as with 1000 & 0."); + def->sidetext = def_infill_anchor_min->sidetext; + def->ratio_over = def_infill_anchor_min->ratio_over; + def->gui_type = def_infill_anchor_min->gui_type; + def->enum_values = def_infill_anchor_min->enum_values; + def->max_literal = def_infill_anchor_min->max_literal; + def->enum_labels.push_back(L("0 (Simple connect)")); + def->enum_labels.push_back("1 mm"); + def->enum_labels.push_back("2 mm"); + def->enum_labels.push_back("5 mm"); + def->enum_labels.push_back("10 mm"); + def->enum_labels.push_back(L("1000 (unlimited)")); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloatOrPercent(20, false)); + def = this->add("outer_wall_acceleration", coFloat); def->label = L("Outer wall"); def->tooltip = L("Acceleration of outer walls"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index ea78f20863..5ac32bae60 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -780,9 +780,8 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloat, small_perimeter_threshold)) ((ConfigOptionFloat, top_solid_infill_flow_ratio)) ((ConfigOptionFloat, bottom_solid_infill_flow_ratio)) - - - + ((ConfigOptionFloatOrPercent, infill_anchor)) + ((ConfigOptionFloatOrPercent, infill_anchor_max)) ) diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index bbaa16a34f..890d7aab8a 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -831,6 +831,8 @@ bool PrintObject::invalidate_state_by_config_options( || opt_key == "bottom_surface_pattern" || opt_key == "external_fill_link_max_length" || opt_key == "sparse_infill_pattern" + || opt_key == "infill_anchor" + || opt_key == "infill_anchor_max" || opt_key == "top_surface_line_width" || opt_key == "initial_layer_line_width") { steps.emplace_back(posInfill); diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index cef3bc24c9..70562dc0a7 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -547,8 +547,12 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, co bool have_infill = config->option("sparse_infill_density")->value > 0; // sparse_infill_filament uses the same logic as in Print::extruders() for (auto el : { "sparse_infill_pattern", "infill_combination", - "minimum_sparse_infill_area", "sparse_infill_filament"}) + "minimum_sparse_infill_area", "sparse_infill_filament", "infill_anchor_max"}) toggle_line(el, have_infill); + + // Only allow configuration of open anchors if the anchoring is enabled. + bool has_infill_anchors = have_infill && config->option("infill_anchor_max")->value > 0; + toggle_field("infill_anchor", has_infill_anchors); bool has_spiral_vase = config->opt_bool("spiral_mode"); bool has_top_solid_infill = config->opt_int("top_shell_layers") > 0; diff --git a/src/slic3r/GUI/GUI_Factories.cpp b/src/slic3r/GUI/GUI_Factories.cpp index bd28915c27..624a89d694 100644 --- a/src/slic3r/GUI/GUI_Factories.cpp +++ b/src/slic3r/GUI/GUI_Factories.cpp @@ -95,7 +95,7 @@ std::map> SettingsFactory::PART_CAT }}, { L("Strength"), {{"wall_loops", "",1},{"top_shell_layers", L("Top Solid Layers"),1},{"top_shell_thickness", L("Top Minimum Shell Thickness"),1}, {"bottom_shell_layers", L("Bottom Solid Layers"),1}, {"bottom_shell_thickness", L("Bottom Minimum Shell Thickness"),1}, - {"sparse_infill_density", "",1},{"sparse_infill_pattern", "",1},{"top_surface_pattern", "",1},{"bottom_surface_pattern", "",1}, + {"sparse_infill_density", "",1},{"sparse_infill_pattern", "",1},{"infill_anchor", "",1},{"infill_anchor_max", "",1},{"top_surface_pattern", "",1},{"bottom_surface_pattern", "",1}, {"infill_combination", "",1}, {"infill_wall_overlap", "",1}, {"infill_direction", "",1}, {"bridge_angle", "",1}, {"minimum_sparse_infill_area", "",1} }}, { L("Speed"), {{"outer_wall_speed", "",1},{"inner_wall_speed", "",2},{"sparse_infill_speed", "",3},{"top_surface_speed", "",4}, {"internal_solid_infill_speed", "",5}, diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index d003969d5c..497ef553d0 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1905,6 +1905,9 @@ void TabPrint::build() optgroup = page->new_optgroup(L("Infill"), L"param_infill"); optgroup->append_single_option_line("sparse_infill_density"); optgroup->append_single_option_line("sparse_infill_pattern", "fill-patterns#infill types and their properties of sparse"); + optgroup->append_single_option_line("infill_anchor"); + optgroup->append_single_option_line("infill_anchor_max"); + optgroup->append_single_option_line("filter_out_gap_fill"); optgroup = page->new_optgroup(L("Advanced"), L"param_advanced");