Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add small perimeter length in user interface #4593

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Slic3r/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ sub validate {
# --perimeters
die "Invalid value for --perimeters\n"
if $self->perimeters < 0;

die "Invalid value for --small-perimeter-length\n"
if $self->perimeters < 0;

# --solid-layers
die "Invalid value for --solid-layers\n" if defined $self->solid_layers && $self->solid_layers < 0;
Expand Down
10 changes: 5 additions & 5 deletions lib/Slic3r/GUI/PresetEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ sub options {
infill_every_layers infill_only_where_needed
solid_infill_every_layers fill_angle solid_infill_below_area
only_retract_when_crossing_perimeters infill_first
max_print_speed max_volumetric_speed
max_print_speed max_volumetric_speed small_perimeter_length
perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed
solid_infill_speed top_solid_infill_speed support_material_speed
support_material_interface_speed bridge_speed gap_fill_speed
Expand Down Expand Up @@ -631,9 +631,9 @@ sub build {
{
my $optgroup = $page->new_optgroup('Speed for print moves');
$optgroup->append_single_option_line($_, undef, width => 100)
for qw(perimeter_speed small_perimeter_speed external_perimeter_speed
infill_speed solid_infill_speed top_solid_infill_speed
gap_fill_speed bridge_speed
for qw(perimeter_speed small_perimeter_speed small_perimeter_length
external_perimeter_speed infill_speed solid_infill_speed
top_solid_infill_speed gap_fill_speed bridge_speed
support_material_speed support_material_interface_speed
);
}
Expand Down Expand Up @@ -887,7 +887,7 @@ sub _update {
if (any { /$opt_key/ } qw(all_keys perimeters)) {
$self->get_field($_)->toggle($have_perimeters)
for qw(extra_perimeters thin_walls overhangs seam_position external_perimeters_first
external_perimeter_extrusion_width
external_perimeter_extrusion_width small_perimeter_length
perimeter_speed small_perimeter_speed external_perimeter_speed);
}

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ set(SLIC3R_TEST_SOURCES
${TESTDIR}/libslic3r/test_test_data.cpp
${TESTDIR}/libslic3r/test_geometry.cpp
${TESTDIR}/libslic3r/test_gcodewriter.cpp
${TESTDIR}/libslic3r/test_gcode.cpp
)

add_executable(slic3r slic3r.cpp)
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Dialogs/PresetEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class PrintEditor : public PresetEditor {
{
"layer_height"s, "first_layer_height"s,
"adaptive_slicing"s, "adaptive_slicing_quality"s, "match_horizontal_surfaces"s,
"perimeters"s, "spiral_vase"s,
"perimeters"s, "spiral_vase"s, "small_perimeter_length"s,
"top_solid_layers"s, "bottom_solid_layers"s,
"extra_perimeters"s, "avoid_crossing_perimeters"s, "thin_walls"s, "overhangs"s,
"seam_position"s, "external_perimeters_first"s,
Expand Down
2 changes: 1 addition & 1 deletion src/test/inputs/test_config/config_bundle_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ skirt_distance = 6
skirt_height = 1
skirts = 1
small_perimeter_speed = 15
small_perimeter_length = 40
solid_infill_below_area = 70
solid_infill_every_layers = 0
solid_infill_extruder = 1
Expand Down Expand Up @@ -173,7 +174,6 @@ shortcuts = support_material
skirt_distance = 6
skirt_height = 1
skirts = 1
small_perimeter_speed = 15
solid_infill_below_area = 70
solid_infill_every_layers = 0
solid_infill_extruder = 1
Expand Down
61 changes: 61 additions & 0 deletions src/test/libslic3r/test_gcode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <catch.hpp>
#include "GCodeWriter.hpp"
#include "GCodeReader.hpp"
#include "test_options.hpp"
#include "test_data.hpp"

using namespace Slic3r;
using namespace Slic3r::Test;
using namespace std::literals::string_literals;

SCENARIO( "Small perimeter gcode speeds" ) {
auto gcode {std::stringstream("")};
GIVEN( "A cylinder with diameter 10mm, and a config that sets 1 perimeter, no infill, external speed = 100mm/s and small perimeter speed = 15mm/s") {
config_ptr test_config = Slic3r::Config::new_from_defaults();
test_config->set("small_perimeter_length", 10);
test_config->set("external_perimeter_speed", 100);
test_config->set("perimeters", 1);
test_config->set("fill_density", "0%");
test_config->set("top_solid_layers", 0);
test_config->set("gcode_comments", true);
test_config->set("cooling", false);
Model test_model;
auto print {Slic3r::Test::init_print({TriangleMesh::make_cylinder(10, 10)}, test_model, test_config)};
WHEN( "slicing the model with small_perimeter_length = 6.5" ) {
print->process();
Slic3r::Test::gcode(gcode, print);
auto exported {gcode.str()};
THEN( "the speed chosen for the second layer's perimeter is 6000mm/minute in gcode (F6000)." ) {
int speed = 0;
auto reader {GCodeReader()};
reader.apply_config(print-> config);
reader.parse(exported, [&speed] (GCodeReader& self, const GCodeReader::GCodeLine& line)
{
speed = self.F;
// code to read speed from gcode goes here, see
// https://github.com/slic3r/Slic3r/blob/master/xs/src/libslic3r/GCodeReader.hpp
// for documentation of GCodeReader and GCodeLine
// and test_printgcode.cpp for examples in how it's used.
});
REQUIRE(speed == 6000);
}
}
// WHEN( "slicing the model with small_perimeter_length = 15" ) {
// test_config->set("small_perimeter_length", 15);
// THEN( "the speed used for the second layer's perimeter is 900mm/minute in gcode (F900)." ) {
// int speed = 0;
// auto reader {GCodeReader()};
// reader.apply_config(print->config);
// reader.parse(exported, [&speed] (GCodeReader& self, const GCodeReader::GCodeLine& line)
// {
// speed = self.F;
// // code to read speed from gcode goes here, see
// // https://github.com/slic3r/Slic3r/blob/master/xs/src/libslic3r/GCodeReader.hpp
// // for documentation of GCodeReader and GCodeLine
// // and test_printgcode.cpp for examples in how it's used.
// });
// REQUIRE(speed == 900);
// }
// }// when
}
}
2 changes: 1 addition & 1 deletion xs/src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed)
// apply the small perimeter speed
if (paths.front().is_perimeter()
&& !loop.has(erOverhangPerimeter)
&& loop.length() <= SMALL_PERIMETER_LENGTH
&& loop.length() <= scale_(this->config.get_abs_value("small_perimeter_length") * 2 * PI)
&& speed == -1) {
speed = this->config.get_abs_value("small_perimeter_speed");
description = "small perimeter";
Expand Down
9 changes: 9 additions & 0 deletions xs/src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,15 @@ PrintConfigDef::PrintConfigDef()
def->enum_labels.push_back("auto");
def->default_value = new ConfigOptionFloatOrPercent(15, false);

def = this->add("small_perimeter_length", coFloat);
def->label = __TRANS("Small perimeter length");
def->category = __TRANS("Layers and Perimeters");
def->tooltip = __TRANS("This setting controls the lenghtof the small perimeters");
def->sidetext = "mm";
def->cli = "small-perimeter-length=f";
def->min = 0;
def->default_value = new ConfigOptionFloat(6.5);

def = this->add("solid_infill_below_area", coFloat);
def->label = __TRANS("Solid infill threshold area");
def->category = __TRANS("Infill");
Expand Down
2 changes: 2 additions & 0 deletions xs/src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig
ConfigOptionFloat perimeter_speed;
ConfigOptionInt perimeters;
ConfigOptionFloatOrPercent small_perimeter_speed;
ConfigOptionFloat small_perimeter_length;
ConfigOptionFloat solid_infill_below_area;
ConfigOptionInt solid_infill_extruder;
ConfigOptionFloatOrPercent solid_infill_extrusion_width;
Expand Down Expand Up @@ -305,6 +306,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig
OPT_PTR(perimeter_speed);
OPT_PTR(perimeters);
OPT_PTR(small_perimeter_speed);
OPT_PTR(small_perimeter_length);
OPT_PTR(solid_infill_below_area);
OPT_PTR(solid_infill_extruder);
OPT_PTR(solid_infill_extrusion_width);
Expand Down
1 change: 0 additions & 1 deletion xs/src/libslic3r/libslic3r.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ constexpr auto PI = 3.141592653589793238;
// When extruding a closed loop, the loop is interrupted and shortened a bit to reduce the seam.
constexpr auto LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER = 0.15;
// Maximum perimeter length for the loop to apply the small perimeter speed.
constexpr coord_t SMALL_PERIMETER_LENGTH = scale_(6.5) * 2 * PI;
constexpr coordf_t INSET_OVERLAP_TOLERANCE = 0.4;
constexpr coordf_t EXTERNAL_INFILL_MARGIN = 3;
constexpr coord_t SCALED_EXTERNAL_INFILL_MARGIN = scale_(EXTERNAL_INFILL_MARGIN);
Expand Down