From 19eea19d916d2b45ca45e22cf34e4e148ac477a1 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 26 Nov 2016 01:02:51 -0600 Subject: [PATCH 01/96] Filament-specific start and end gcode. GUI page copied from Printer settings. --- lib/Slic3r/GUI/Tab.pm | 24 ++++++++++++++++++++++++ lib/Slic3r/Print/GCode.pm | 6 ++++++ xs/src/libslic3r/PrintConfig.cpp | 26 ++++++++++++++++++++++++++ xs/src/libslic3r/PrintConfig.hpp | 4 ++++ 4 files changed, 60 insertions(+) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 259ec7752..8ca5bcb41 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -893,6 +893,7 @@ sub build { fan_always_on cooling min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers fan_below_layer_time slowdown_below_layer_time min_print_speed + start_filament_gcode end_filament_gcode )); $self->{config}->set('filament_settings_id', ''); @@ -905,6 +906,8 @@ sub build { $optgroup->append_single_option_line('extrusion_multiplier', 0); } + + { my $optgroup = $page->new_optgroup('Temperature (°C)'); @@ -990,6 +993,27 @@ sub build { $optgroup->append_single_option_line($option); } } + { + my $page = $self->add_options_page('Custom G-code', 'cog.png'); + { + my $optgroup = $page->new_optgroup('Start G-code', + label_width => 0, + ); + my $option = $optgroup->get_option('start_filament_gcode', 0); + $option->full_width(1); + $option->height(150); + $optgroup->append_single_option_line($option); + } + { + my $optgroup = $page->new_optgroup('End G-code', + label_width => 0, + ); + my $option = $optgroup->get_option('end_filament_gcode', 0); + $option->full_width(1); + $option->height(150); + $optgroup->append_single_option_line($option); + } + } } sub _update { diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 3c32875ed..73fa8baca 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -169,6 +169,9 @@ sub export { # set extruder(s) temperature before and after start G-code $self->_print_first_layer_temperature(0); printf $fh "%s\n", $gcodegen->placeholder_parser->process($self->config->start_gcode); + foreach my $start_gcode (@{ $self->config->start_filament_gcode }) { # process filament gcode in order + printf $fh "%s\n", $gcodegen->placeholder_parser->process($start_gcode); + } $self->_print_first_layer_temperature(1); # set other general things @@ -302,6 +305,9 @@ sub export { # write end commands to file print $fh $gcodegen->retract; # TODO: process this retract through PressureRegulator in order to discharge fully print $fh $gcodegen->writer->set_fan(0); + foreach my $end_gcode (@{ $self->config->end_filament_gcode }) { # Process filament-specific gcode in extruder order. + printf $fh "%s\n", $gcodegen->placeholder_parser->process($end_gcode); + } printf $fh "%s\n", $gcodegen->placeholder_parser->process($self->config->end_gcode); print $fh $gcodegen->writer->update_progress($gcodegen->layer_count, $gcodegen->layer_count, 1); # 100% print $fh $gcodegen->writer->postamble; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index a93fcd00f..9dcfc0680 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -149,6 +149,19 @@ PrintConfigDef::PrintConfigDef() def->height = 120; def->default_value = new ConfigOptionString("M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n"); + def = this->add("end_filament_gcode", coStrings); + def->label = "End G-code"; + def->tooltip = "This end procedure is inserted at the end of the output file, before the printer end gcode. Note that you can use placeholder variables for all Slic3r settings. If you have multiple extruders, the gcode is processed in extruder order."; + def->cli = "end-filament-gcode=s@"; + def->multiline = true; + def->full_width = true; + def->height = 120; + { + ConfigOptionStrings* opt = new ConfigOptionStrings(); + opt->values.push_back("; Filament-specific end gcode \n;END gcode for filament\n"); + def->default_value = opt; + } + def = this->add("external_fill_pattern", coEnum); def->label = "Top/bottom fill pattern"; def->category = "Infill"; @@ -1083,6 +1096,19 @@ PrintConfigDef::PrintConfigDef() def->height = 120; def->default_value = new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n"); + def = this->add("start_filament_gcode", coStrings); + def->label = "Start G-code"; + def->tooltip = "This start procedure is inserted at the beginning, after any printer start gcode. This is used to override settings for a specific filament. If Slic3r detects M104, M109, M140 or M190 in your custom codes, such commands will not be prepended automatically so you're free to customize the order of heating commands and other custom actions. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want. If you have multiple extruders, the gcode is processed in extruder order."; + def->cli = "start-filament-gcode=s@"; + def->multiline = true; + def->full_width = true; + def->height = 120; + { + ConfigOptionStrings* opt = new ConfigOptionStrings(); + opt->values.push_back("; Filament gcode\n"); + def->default_value = opt; + } + def = this->add("support_material", coBool); def->label = "Generate support material"; def->category = "Support material"; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 0c402e50a..15f442833 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -286,6 +286,7 @@ class GCodeConfig : public virtual StaticPrintConfig public: ConfigOptionString before_layer_gcode; ConfigOptionString end_gcode; + ConfigOptionStrings end_filament_gcode; ConfigOptionString extrusion_axis; ConfigOptionFloats extrusion_multiplier; ConfigOptionFloats filament_diameter; @@ -305,6 +306,7 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionFloats retract_restart_extra_toolchange; ConfigOptionFloats retract_speed; ConfigOptionString start_gcode; + ConfigOptionStrings start_filament_gcode; ConfigOptionString toolchange_gcode; ConfigOptionFloat travel_speed; ConfigOptionBool use_firmware_retraction; @@ -319,6 +321,7 @@ class GCodeConfig : public virtual StaticPrintConfig virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(before_layer_gcode); OPT_PTR(end_gcode); + OPT_PTR(end_filament_gcode); OPT_PTR(extrusion_axis); OPT_PTR(extrusion_multiplier); OPT_PTR(filament_diameter); @@ -338,6 +341,7 @@ class GCodeConfig : public virtual StaticPrintConfig OPT_PTR(retract_restart_extra_toolchange); OPT_PTR(retract_speed); OPT_PTR(start_gcode); + OPT_PTR(start_filament_gcode); OPT_PTR(toolchange_gcode); OPT_PTR(travel_speed); OPT_PTR(use_firmware_retraction); From a42c16450bf5b3a1bbd748e01d556916d77c387d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 26 Jan 2017 20:03:42 -0600 Subject: [PATCH 02/96] Reduces the maximum flow for internal infill to 3x nozzle diameter (avoid absurdly wide traces at small layer heights). Fixes #3688 Fixes #2599 --- xs/src/libslic3r/Flow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/Flow.cpp b/xs/src/libslic3r/Flow.cpp index 6b3d1986c..6131534e7 100644 --- a/xs/src/libslic3r/Flow.cpp +++ b/xs/src/libslic3r/Flow.cpp @@ -91,14 +91,14 @@ Flow::_auto_width(FlowRole role, float nozzle_diameter, float height) { float width = ((nozzle_diameter*nozzle_diameter) * PI + (height*height) * (4.0 - PI)) / (4.0 * height); float min = nozzle_diameter * 1.05; - float max = -1; + float max = nozzle_diameter * 3; // cap width to 3x nozzle diameter if (role == frExternalPerimeter || role == frSupportMaterial || role == frSupportMaterialInterface) { min = max = nozzle_diameter; } else if (role != frInfill) { // do not limit width for sparse infill so that we use full native flow for it max = nozzle_diameter * 1.7; } - if (max != -1 && width > max) width = max; + if (width > max) width = max; if (width < min) width = min; return width; From 798b6c8a08ce812d7a220482308e9d15493a22d3 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 7 Mar 2017 20:34:42 -0600 Subject: [PATCH 03/96] Silenced curl, returns 0 when done --- package/deploy-bintray.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package/deploy-bintray.sh b/package/deploy-bintray.sh index efb3f405f..c24fa62b8 100755 --- a/package/deploy-bintray.sh +++ b/package/deploy-bintray.sh @@ -59,11 +59,12 @@ API=${BINTRAY_API_KEY} USER=${BINTRAY_API_USER} echo "Creating version: $version" -curl -X POST -d "{ \"name\": \"$version\", \"released\": \"ISO8601 $(date +%Y-%m-%d'T'%H:%M:%S)\", \"desc\": \"This version...\", \"github_release_notes_file\": \"RELEASE.txt\", \"github_use_tag_release_notes\": true, \"vcs_tag\": \"$version\" }" -u${USER}:${API} https://api.bintray.com/content/lordofhyphens/Slic3r/${SLIC3R_PKG}/versions +curl -s -X POST -d "{ \"name\": \"$version\", \"released\": \"ISO8601 $(date +%Y-%m-%d'T'%H:%M:%S)\", \"desc\": \"This version...\", \"github_release_notes_file\": \"RELEASE.txt\", \"github_use_tag_release_notes\": true, \"vcs_tag\": \"$version\" }" -u${USER}:${API} https://api.bintray.com/content/lordofhyphens/Slic3r/${SLIC3R_PKG}/versions echo "Publishing ${file} to ${version}..." -curl -H "X-Bintray-Package: $SLIC3R_PKG" -H "X-Bintray-Version: $version" -H 'X-Bintray-Publish: 1' -H 'X-Bintray-Override: 1' -T $file -u${USER}:${API} https://api.bintray.com/content/lordofhyphens/Slic3r/$(basename $1) +curl -s -H "X-Bintray-Package: $SLIC3R_PKG" -H "X-Bintray-Version: $version" -H 'X-Bintray-Publish: 1' -H 'X-Bintray-Override: 1' -T $file -u${USER}:${API} https://api.bintray.com/content/lordofhyphens/Slic3r/$(basename $1) #curl -X POST -u${USER}:${API} https://api.bintray.com/content/lordofhyphens/Slic3r/${SLIC3R_PKG}/$version/publish # Wait 5s for the server to catch up #sleep 5 #curl -H 'Content-Type: application/json' -X PUT -d "{ \"list_in_downloads\":true }" -u${USER}:${API} https://api.bintray.com/file_metadata/lordofhyphens/Slic3r/$(basename $1) +exit 0 From bb214b0cd626dc4ace15c6fce9ed7d37bd83f6b0 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 8 Mar 2017 14:40:00 +0100 Subject: [PATCH 04/96] Trigger extra perimeters also when a diagonal gap would be visible. #3732 --- lib/Slic3r/Test.pm | 7 +++++ t/shells.t | 22 +++++++++++++++- xs/src/libslic3r/PerimeterGenerator.cpp | 3 +-- xs/src/libslic3r/PrintObject.cpp | 34 +++++++++++++++---------- xs/src/libslic3r/SurfaceCollection.hpp | 1 + 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/lib/Slic3r/Test.pm b/lib/Slic3r/Test.pm index 4b4d35520..dbd2d37f1 100644 --- a/lib/Slic3r/Test.pm +++ b/lib/Slic3r/Test.pm @@ -133,6 +133,13 @@ sub mesh { $facets = [ [0,1,2],[1,0,3],[2,1,4],[2,5,0],[0,6,3],[1,3,7],[1,8,4],[4,9,2],[10,5,2],[5,6,0],[6,11,3],[3,12,7],[7,8,1],[4,8,11],[4,11,9],[9,10,2],[10,13,5],[14,6,5],[9,11,6],[11,12,3],[12,8,7],[11,8,15],[13,10,9],[5,13,14],[14,13,6],[6,13,9],[15,12,11],[15,8,12] ]; + } elsif ($name eq 'step') { + $vertices = [ + [0,20,5],[0,20,0],[0,0,5],[0,0,0],[20,0,0],[20,0,5],[1,19,5],[1,1,5],[19,1,5],[20,20,5],[19,19,5],[20,20,0],[19,19,10],[1,19,10],[1,1,10],[19,1,10] + ]; + $facets = [ + [0,1,2],[1,3,2],[3,4,5],[2,3,5],[6,0,2],[6,2,7],[5,8,7],[5,7,2],[9,10,8],[9,8,5],[9,0,6],[9,6,10],[9,11,1],[9,1,0],[3,1,11],[4,3,11],[5,11,9],[5,4,11],[12,10,6],[12,6,13],[6,7,14],[13,6,14],[7,8,15],[14,7,15],[15,8,10],[15,10,12],[12,13,14],[12,14,15] + ]; } else { return undef; } diff --git a/t/shells.t b/t/shells.t index e6eb65a9d..63eb1905d 100644 --- a/t/shells.t +++ b/t/shells.t @@ -1,4 +1,4 @@ -use Test::More tests => 21; +use Test::More tests => 24; use strict; use warnings; @@ -11,6 +11,7 @@ BEGIN { use List::Util qw(first sum); use Slic3r; use Slic3r::Geometry qw(epsilon); +use Slic3r::Surface qw(S_TYPE_TOP); use Slic3r::Test; { @@ -318,4 +319,23 @@ use Slic3r::Test; is $diagonal_moves, 0, 'no spiral moves on two-island object'; } +{ + # GH: #3732 + my $config = Slic3r::Config->new_from_defaults; + $config->set('perimeters', 2); + $config->set('extrusion_width', 0.55); + $config->set('first_layer_height', 0.25); + $config->set('infill_overlap', '50%'); + $config->set('layer_height', 0.25); + $config->set('perimeters', 2); + $config->set('extra_perimeters', 1); + + my $tprint = Slic3r::Test::init_print('step', config => $config); + $tprint->print->process; + my $layerm19 = $tprint->print->get_object(0)->get_layer(19)->get_region(0); + is scalar(@{$layerm19->slices->filter_by_type(S_TYPE_TOP)}), 1, 'top slice detected'; + is scalar(@{$layerm19->fill_surfaces->filter_by_type(S_TYPE_TOP)}), 0, 'no top fill_surface detected'; + is $layerm19->perimeters->items_count, 3, 'extra perimeter detected'; +} + __END__ diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index ce24e1a7f..b902f5307 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -315,8 +315,7 @@ PerimeterGenerator::process() ); // append infill areas to fill_surfaces - for (ExPolygons::const_iterator ex = expp.begin(); ex != expp.end(); ++ex) - this->fill_surfaces->surfaces.push_back(Surface(stInternal, *ex)); // use a bogus surface type + this->fill_surfaces->append(expp, stInternal); // use a bogus surface type } } } diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 4f38cfa1d..0b420e6a3 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -384,7 +384,7 @@ PrintObject::detect_surfaces_type() const Layer* lower_layer = layer_idx > 0 ? this->get_layer(layer_idx-1) : NULL; // collapse very narrow parts (using the safety offset in the diff is not enough) - const float offset = layerm.flow(frExternalPerimeter).scaled_width() / 10.f; + const float offs = layerm.flow(frExternalPerimeter).scaled_width() / 10.f; const Polygons layerm_slices_surfaces = layerm.slices; @@ -392,14 +392,14 @@ PrintObject::detect_surfaces_type() // of current layer and upper one) SurfaceCollection top; if (upper_layer != NULL) { - const Polygons upper_slices = this->config.interface_shells.value + Polygons upper_slices = this->config.interface_shells.value ? (Polygons)upper_layer->get_region(region_id)->slices : (Polygons)upper_layer->slices; top.append( offset2_ex( diff(layerm_slices_surfaces, upper_slices, true), - -offset, offset + -offs, offs ), stTop ); @@ -426,7 +426,7 @@ PrintObject::detect_surfaces_type() bottom.append( offset2_ex( diff(layerm_slices_surfaces, lower_layer->slices, true), - -offset, offset + -offs, offs ), surface_type_bottom ); @@ -443,7 +443,7 @@ PrintObject::detect_surfaces_type() lower_layer->get_region(region_id)->slices, true ), - -offset, offset + -offs, offs ), stBottom ); @@ -470,7 +470,7 @@ PrintObject::detect_surfaces_type() const Polygons top_polygons = to_polygons(STDMOVE(top)); top.clear(); top.append( - offset2_ex(diff(top_polygons, bottom, true), -offset, offset), + offset2_ex(diff(top_polygons, bottom, true), -offs, offs), stTop ); } @@ -487,17 +487,18 @@ PrintObject::detect_surfaces_type() layerm.slices.append( offset2_ex( diff(layerm_slices_surfaces, topbottom, true), - -offset, offset + -offs, offs ), stInternal ); } - /* - Slic3r::debugf " layer %d has %d bottom, %d top and %d internal surfaces\n", - $layerm->layer->id, scalar(@bottom), scalar(@top), scalar(@internal) if $Slic3r::debug; - */ - + #ifdef SLIC3R_DEBUG + printf(" layer %zu has %zu bottom, %zu top and %zu internal surfaces\n", + layerm.layer()->id(), bottom.size(), top.size(), + layerm.slices.size()-bottom.size()-top.size()); + #endif + } // for each layer of a region /* Fill in layerm->fill_surfaces by trimming the layerm->slices by the cummulative layerm->fill_surfaces. @@ -782,7 +783,6 @@ PrintObject::_make_perimeters() size_t region_id = region_it - this->_print->regions.begin(); const PrintRegion ®ion = **region_it; - if (!region.config.extra_perimeters || region.config.perimeters == 0 || region.config.fill_density == 0 @@ -791,7 +791,13 @@ PrintObject::_make_perimeters() for (size_t i = 0; i <= (this->layer_count()-2); ++i) { LayerRegion &layerm = *this->get_layer(i)->get_region(region_id); const LayerRegion &upper_layerm = *this->get_layer(i+1)->get_region(region_id); - const Polygons upper_layerm_polygons = upper_layerm.slices; + + // In order to avoid diagonal gaps (GH #3732) we ignore the external half of the upper + // perimeter, since it's not truly covering this layer. + const Polygons upper_layerm_polygons = offset( + upper_layerm.slices, + -upper_layerm.flow(frExternalPerimeter).scaled_width()/2 + ); // Filter upper layer polygons in intersection_ppl by their bounding boxes? // my $upper_layerm_poly_bboxes= [ map $_->bounding_box, @{$upper_layerm_polygons} ]; diff --git a/xs/src/libslic3r/SurfaceCollection.hpp b/xs/src/libslic3r/SurfaceCollection.hpp index e9d42fc49..6c4fe05a7 100644 --- a/xs/src/libslic3r/SurfaceCollection.hpp +++ b/xs/src/libslic3r/SurfaceCollection.hpp @@ -29,6 +29,7 @@ class SurfaceCollection void append(const ExPolygons &src, SurfaceType surfaceType); size_t polygons_count() const; bool empty() const { return this->surfaces.empty(); }; + size_t size() const { return this->surfaces.size(); }; void clear() { this->surfaces.clear(); }; }; From 412498b8e408ba57e7a6fec8cdf413b5e5899a99 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 3 Mar 2017 12:54:00 +0100 Subject: [PATCH 05/96] Reverted unification of positive and negative zeros when loaded from an STL file. Conflicts: xs/src/admesh/stlinit.c --- xs/src/admesh/stlinit.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/xs/src/admesh/stlinit.c b/xs/src/admesh/stlinit.c index 54f5b836c..a191e3d76 100644 --- a/xs/src/admesh/stlinit.c +++ b/xs/src/admesh/stlinit.c @@ -318,6 +318,28 @@ stl_read(stl_file *stl, int first_facet, int first) { } #endif +#if 1 + { + // Positive and negative zeros are possible in the floats, which are considered equal by the FP unit. + // When using a memcmp on raw floats, those numbers report to be different. + // Unify all +0 and -0 to +0 to make the floats equal under memcmp. + uint32_t *f = (uint32_t*)&facet; + for (int j = 0; j < 12; ++ j, ++ f) // 3x vertex + normal: 4x3 = 12 floats + if (*f == 0x80000000) + // Negative zero, switch to positive zero. + *f = 0; + } +#else + { + // Due to the nature of the floating point numbers, close to zero values may be represented with singificantly higher precision + // than the rest of the vertices. Round them to zero. + float *f = (float*)&facet; + for (int j = 0; j < 12; ++ j, ++ f) // 3x vertex + normal: 4x3 = 12 floats + if (*f > -1e-12f && *f < 1e-12f) + // Negative zero, switch to positive zero. + *f = 0; + } +#endif /* Write the facet into memory. */ memcpy(stl->facet_start+i, &facet, SIZEOF_STL_FACET); stl_facet_stats(stl, facet, first); From c4929c315f958c597b7e4dfc975117852db97507 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 2 Mar 2017 16:39:43 +0100 Subject: [PATCH 06/96] Fix of #117: A large fractal pyramid takes ages to slice The Clipper library has difficulties processing overlapping polygons. Namely, the function Clipper::JoinCommonEdges() has potentially a terrible time complexity if the output of the operation is of the PolyTree type. This function implmenets a following workaround: 1) Peform the Clipper operation with the output to Paths. This method handles overlaps in a reasonable time. 2) Run Clipper Union once again to extract the PolyTree from the result of 1). Conflicts: xs/src/libslic3r/ClipperUtils.cpp --- xs/src/libslic3r/ClipperUtils.cpp | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index 08a4df17e..ce45dcc12 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -295,6 +295,43 @@ _clipper_do(const ClipperLib::ClipType clipType, const Polygons &subject, return retval; } +// The Clipper library has difficulties processing overlapping polygons. +// Namely, the function Clipper::JoinCommonEdges() has potentially a terrible time complexity if the output +// of the operation is of the PolyTree type. +// This function implements a following workaround: +// 1) Peform the Clipper operation with the output to Paths. This method handles overlaps in a reasonable time. +// 2) Run Clipper Union once again to extract the PolyTree from the result of 1). +inline ClipperLib::PolyTree _clipper_do_polytree2(const ClipperLib::ClipType clipType, const Polygons &subject, + const Polygons &clip, const ClipperLib::PolyFillType fillType, const bool safety_offset_) +{ + // read input + ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject); + ClipperLib::Paths input_clip = Slic3rMultiPoints_to_ClipperPaths(clip); + + // perform safety offset + if (safety_offset_) { + if (clipType == ClipperLib::ctUnion) { + safety_offset(&input_subject); + } else { + safety_offset(&input_clip); + } + } + + ClipperLib::Clipper clipper; + clipper.AddPaths(input_subject, ClipperLib::ptSubject, true); + clipper.AddPaths(input_clip, ClipperLib::ptClip, true); + // Perform the operation with the output to input_subject. + // This pass does not generate a PolyTree, which is a very expensive operation with the current Clipper library + // if there are overlapping edges. + clipper.Execute(clipType, input_subject, fillType, fillType); + // Perform an additional Union operation to generate the PolyTree ordering. + clipper.Clear(); + clipper.AddPaths(input_subject, ClipperLib::ptSubject, true); + ClipperLib::PolyTree retval; + clipper.Execute(ClipperLib::ctUnion, retval, fillType, fillType); + return retval; +} + ClipperLib::PolyTree _clipper_do(const ClipperLib::ClipType clipType, const Polylines &subject, const Polygons &clip, const ClipperLib::PolyFillType fillType, @@ -337,7 +374,7 @@ _clipper_ex(ClipperLib::ClipType clipType, const Polygons &subject, const Polygons &clip, bool safety_offset_) { // perform operation - ClipperLib::PolyTree polytree = _clipper_do(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_); + ClipperLib::PolyTree polytree = _clipper_do_polytree2(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_); // convert into ExPolygons return PolyTreeToExPolygons(polytree); From 306264c214b38d871a167b0d04ea6b86503b252a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 8 Mar 2017 15:43:32 +0100 Subject: [PATCH 07/96] Write scaling_factor to AMF files (by @bubnikv) --- xs/src/libslic3r/IO/AMF.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/IO/AMF.cpp b/xs/src/libslic3r/IO/AMF.cpp index d2708764f..32471e105 100644 --- a/xs/src/libslic3r/IO/AMF.cpp +++ b/xs/src/libslic3r/IO/AMF.cpp @@ -87,11 +87,12 @@ struct AMFParserContext NODE_TYPE_DELTAX, // amf/constellation/instance/deltax NODE_TYPE_DELTAY, // amf/constellation/instance/deltay NODE_TYPE_RZ, // amf/constellation/instance/rz + NODE_TYPE_SCALE, // amf/constellation/instance/scale NODE_TYPE_METADATA, // anywhere under amf/*/metadata }; struct Instance { - Instance() : deltax_set(false), deltay_set(false), rz_set(false) {} + Instance() : deltax_set(false), deltay_set(false), rz_set(false), scale_set(false) {} // Shift in the X axis. float deltax; bool deltax_set; @@ -101,6 +102,9 @@ struct AMFParserContext // Rotation around the Z axis. float rz; bool rz_set; + // Scaling factor + float scale; + bool scale_set; }; struct Object { @@ -210,6 +214,8 @@ void AMFParserContext::startElement(const char *name, const char **atts) node_type_new = NODE_TYPE_DELTAY; else if (strcmp(name, "rz") == 0) node_type_new = NODE_TYPE_RZ; + else if (strcmp(name, "scale") == 0) + node_type_new = NODE_TYPE_SCALE; } break; case 4: @@ -266,7 +272,7 @@ void AMFParserContext::characters(const XML_Char *s, int len) { switch (m_path.size()) { case 4: - if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_RZ) + if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_RZ || m_path.back() == NODE_TYPE_SCALE) m_value[0].append(s, len); break; case 6: @@ -312,6 +318,12 @@ void AMFParserContext::endElement(const char *name) m_instance->rz_set = true; m_value[0].clear(); break; + case NODE_TYPE_SCALE: + assert(m_instance); + m_instance->scale = float(atof(m_value[0].c_str())); + m_instance->scale_set = true; + m_value[0].clear(); + break; // Object vertices: case NODE_TYPE_VERTEX: @@ -426,6 +438,7 @@ void AMFParserContext::endDocument() mi->offset.x = instance.deltax; mi->offset.y = instance.deltay; mi->rotation = instance.rz_set ? instance.rz : 0.f; + mi->scaling_factor = instance.scale_set ? instance.scale : 1.f; } } } @@ -564,11 +577,13 @@ AMF::write(Model& model, std::string output_file) " %lf\n" " %lf\n" " %lf\n" + " %lf\n" " \n", object_id, instance->offset.x, instance->offset.y, - instance->rotation); + instance->rotation, + instance->scaling_factor); //FIXME missing instance->scaling_factor instances.append(buf); } From db8396a290c9adc67b45b034e22921c61712fa7a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 9 Mar 2017 20:31:00 +0100 Subject: [PATCH 08/96] Parallelized detect_surfaces_type --- xs/src/libslic3r/Layer.cpp | 172 +++++++++++++++++++++++++++++++ xs/src/libslic3r/Layer.hpp | 4 +- xs/src/libslic3r/PrintObject.cpp | 166 ++--------------------------- 3 files changed, 181 insertions(+), 161 deletions(-) diff --git a/xs/src/libslic3r/Layer.cpp b/xs/src/libslic3r/Layer.cpp index 102654be0..77bc74892 100644 --- a/xs/src/libslic3r/Layer.cpp +++ b/xs/src/libslic3r/Layer.cpp @@ -247,4 +247,176 @@ Layer::make_fills() } } +// This function analyzes slices of a region (SurfaceCollection slices). +// Each region slice (instance of Surface) is analyzed, whether it is supported or whether it is the top surface. +// Initially all slices are of type S_TYPE_INTERNAL. +// Slices are compared against the top / bottom slices and regions and classified to the following groups: +// S_TYPE_TOP - Part of a region, which is not covered by any upper layer. This surface will be filled with a top solid infill. +// S_TYPE_BOTTOMBRIDGE - Part of a region, which is not fully supported, but it hangs in the air, or it hangs losely on a support or a raft. +// S_TYPE_BOTTOM - Part of a region, which is not supported by the same region, but it is supported either by another region, or by a soluble interface layer. +// S_TYPE_INTERNAL - Part of a region, which is supported by the same region type. +// If a part of a region is of S_TYPE_BOTTOM and S_TYPE_TOP, the S_TYPE_BOTTOM wins. +void +Layer::detect_surfaces_type() +{ + PrintObject &object = *this->object(); + + for (size_t region_id = 0; region_id < this->regions.size(); ++region_id) { + LayerRegion &layerm = *this->regions[region_id]; + + // comparison happens against the *full* slices (considering all regions) + // unless internal shells are requested + + // We call layer->slices or layerm->slices on these neighbor layers + // and we convert them into Polygons so we only care about their total + // coverage. We only write to layerm->slices so we can read layer->slices safely. + Layer* const &upper_layer = this->upper_layer; + Layer* const &lower_layer = this->lower_layer; + + // collapse very narrow parts (using the safety offset in the diff is not enough) + const float offs = layerm.flow(frExternalPerimeter).scaled_width() / 10.f; + + const Polygons layerm_slices_surfaces = layerm.slices; + + // find top surfaces (difference between current surfaces + // of current layer and upper one) + SurfaceCollection top; + if (upper_layer != NULL) { + Polygons upper_slices; + if (object.config.interface_shells.value) { + const LayerRegion* upper_layerm = upper_layer->get_region(region_id); + boost::lock_guard l(upper_layerm->_slices_mutex); + upper_slices = upper_layerm->slices; + } else { + upper_slices = upper_layer->slices; + } + + top.append( + offset2_ex( + diff(layerm_slices_surfaces, upper_slices, true), + -offs, offs + ), + stTop + ); + } else { + // if no upper layer, all surfaces of this one are solid + // we clone surfaces because we're going to clear the slices collection + top = layerm.slices; + for (Surface &s : top.surfaces) s.surface_type = stTop; + } + + // find bottom surfaces (difference between current surfaces + // of current layer and lower one) + SurfaceCollection bottom; + if (lower_layer != NULL) { + // If we have soluble support material, don't bridge. The overhang will be squished against a soluble layer separating + // the support from the print. + const SurfaceType surface_type_bottom = + (object.config.support_material.value && object.config.support_material_contact_distance.value == 0) + ? stBottom + : stBottomBridge; + + // Any surface lying on the void is a true bottom bridge (an overhang) + bottom.append( + offset2_ex( + diff(layerm_slices_surfaces, lower_layer->slices, true), + -offs, offs + ), + surface_type_bottom + ); + + // if user requested internal shells, we need to identify surfaces + // lying on other slices not belonging to this region + if (object.config.interface_shells) { + // non-bridging bottom surfaces: any part of this layer lying + // on something else, excluding those lying on our own region + const LayerRegion* lower_layerm = lower_layer->get_region(region_id); + boost::lock_guard l(lower_layerm->_slices_mutex); + bottom.append( + offset2_ex( + diff( + intersection(layerm_slices_surfaces, lower_layer->slices), // supported + lower_layerm->slices, + true + ), + -offs, offs + ), + stBottom + ); + } + } else { + // if no lower layer, all surfaces of this one are solid + // we clone surfaces because we're going to clear the slices collection + bottom = layerm.slices; + + // if we have raft layers, consider bottom layer as a bridge + // just like any other bottom surface lying on the void + const SurfaceType surface_type_bottom = + (object.config.raft_layers.value > 0 && object.config.support_material_contact_distance.value > 0) + ? stBottomBridge + : stBottom; + for (Surface &s : bottom.surfaces) s.surface_type = surface_type_bottom; + } + + // now, if the object contained a thin membrane, we could have overlapping bottom + // and top surfaces; let's do an intersection to discover them and consider them + // as bottom surfaces (to allow for bridge detection) + if (!top.empty() && !bottom.empty()) { + const Polygons top_polygons = to_polygons(STDMOVE(top)); + top.clear(); + top.append( + // TODO: maybe we don't need offset2? + offset2_ex(diff(top_polygons, bottom, true), -offs, offs), + stTop + ); + } + + // save surfaces to layer + { + boost::lock_guard l(layerm._slices_mutex); + layerm.slices.clear(); + layerm.slices.append(STDMOVE(top)); + layerm.slices.append(STDMOVE(bottom)); + + // find internal surfaces (difference between top/bottom surfaces and others) + { + Polygons topbottom = top; append_to(topbottom, (Polygons)bottom); + + layerm.slices.append( + // TODO: maybe we don't need offset2? + offset2_ex( + diff(layerm_slices_surfaces, topbottom, true), + -offs, offs + ), + stInternal + ); + } + } + + #ifdef SLIC3R_DEBUG + printf(" layer %zu has %zu bottom, %zu top and %zu internal surfaces\n", + this->id(), bottom.size(), top.size(), + layerm.slices.size()-bottom.size()-top.size()); + #endif + + { + /* Fill in layerm->fill_surfaces by trimming the layerm->slices by the cummulative layerm->fill_surfaces. + Note: this method should be idempotent, but fill_surfaces gets modified + in place. However we're now only using its boundaries (which are invariant) + so we're safe. This guarantees idempotence of prepare_infill() also in case + that combine_infill() turns some fill_surface into VOID surfaces. */ + const Polygons fill_boundaries = layerm.fill_surfaces; + layerm.fill_surfaces.clear(); + // No other instance of this function is writing to this layer, so we can read safely. + for (const Surface &surface : layerm.slices.surfaces) { + // No other instance of this function modifies fill_surfaces. + layerm.fill_surfaces.append( + intersection_ex(surface, fill_boundaries), + surface.surface_type + ); + } + } + } +} + } diff --git a/xs/src/libslic3r/Layer.hpp b/xs/src/libslic3r/Layer.hpp index c0db224ec..278927e15 100644 --- a/xs/src/libslic3r/Layer.hpp +++ b/xs/src/libslic3r/Layer.hpp @@ -7,6 +7,7 @@ #include "ExtrusionEntityCollection.hpp" #include "ExPolygonCollection.hpp" #include "PolylineCollection.hpp" +#include namespace Slic3r { @@ -66,6 +67,7 @@ class LayerRegion private: Layer *_layer; PrintRegion *_region; + mutable boost::mutex _slices_mutex; LayerRegion(Layer *layer, PrintRegion *region) : _layer(layer), _region(region) {}; @@ -108,12 +110,12 @@ class Layer { template bool any_bottom_region_slice_contains(const T &item) const; void make_perimeters(); void make_fills(); + void detect_surfaces_type(); protected: size_t _id; // sequential number of layer, 0-based PrintObject* _object; - Layer(size_t id, PrintObject *object, coordf_t height, coordf_t print_z, coordf_t slice_z); virtual ~Layer(); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 0b420e6a3..be38fda0a 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -3,6 +3,7 @@ #include "ClipperUtils.hpp" #include "Geometry.hpp" #include +#include namespace Slic3r { @@ -357,169 +358,14 @@ PrintObject::has_support_material() const || this->config.support_material_enforce_layers > 0; } -// This function analyzes slices of a region (SurfaceCollection slices). -// Each region slice (instance of Surface) is analyzed, whether it is supported or whether it is the top surface. -// Initially all slices are of type S_TYPE_INTERNAL. -// Slices are compared against the top / bottom slices and regions and classified to the following groups: -// S_TYPE_TOP - Part of a region, which is not covered by any upper layer. This surface will be filled with a top solid infill. -// S_TYPE_BOTTOMBRIDGE - Part of a region, which is not fully supported, but it hangs in the air, or it hangs losely on a support or a raft. -// S_TYPE_BOTTOM - Part of a region, which is not supported by the same region, but it is supported either by another region, or by a soluble interface layer. -// S_TYPE_INTERNAL - Part of a region, which is supported by the same region type. -// If a part of a region is of S_TYPE_BOTTOM and S_TYPE_TOP, the S_TYPE_BOTTOM wins. void PrintObject::detect_surfaces_type() { - //Slic3r::debugf "Detecting solid surfaces...\n"; - FOREACH_REGION(this->_print, region) { - size_t region_id = region - this->_print->regions.begin(); - - FOREACH_LAYER(this, layer_it) { - size_t layer_idx = layer_it - this->layers.begin(); - Layer &layer = **layer_it; - LayerRegion &layerm = *layer.get_region(region_id); - // comparison happens against the *full* slices (considering all regions) - // unless internal shells are requested - - const Layer* upper_layer = layer_idx < (this->layer_count()-1) ? this->get_layer(layer_idx+1) : NULL; - const Layer* lower_layer = layer_idx > 0 ? this->get_layer(layer_idx-1) : NULL; - - // collapse very narrow parts (using the safety offset in the diff is not enough) - const float offs = layerm.flow(frExternalPerimeter).scaled_width() / 10.f; - - const Polygons layerm_slices_surfaces = layerm.slices; - - // find top surfaces (difference between current surfaces - // of current layer and upper one) - SurfaceCollection top; - if (upper_layer != NULL) { - Polygons upper_slices = this->config.interface_shells.value - ? (Polygons)upper_layer->get_region(region_id)->slices - : (Polygons)upper_layer->slices; - - top.append( - offset2_ex( - diff(layerm_slices_surfaces, upper_slices, true), - -offs, offs - ), - stTop - ); - } else { - // if no upper layer, all surfaces of this one are solid - // we clone surfaces because we're going to clear the slices collection - top = layerm.slices; - for (Surfaces::iterator it = top.surfaces.begin(); it != top.surfaces.end(); ++ it) - it->surface_type = stTop; - } - - // find bottom surfaces (difference between current surfaces - // of current layer and lower one) - SurfaceCollection bottom; - if (lower_layer != NULL) { - // If we have soluble support material, don't bridge. The overhang will be squished against a soluble layer separating - // the support from the print. - const SurfaceType surface_type_bottom = - (this->config.support_material.value && this->config.support_material_contact_distance.value == 0) - ? stBottom - : stBottomBridge; - - // Any surface lying on the void is a true bottom bridge (an overhang) - bottom.append( - offset2_ex( - diff(layerm_slices_surfaces, lower_layer->slices, true), - -offs, offs - ), - surface_type_bottom - ); - - // if user requested internal shells, we need to identify surfaces - // lying on other slices not belonging to this region - if (this->config.interface_shells) { - // non-bridging bottom surfaces: any part of this layer lying - // on something else, excluding those lying on our own region - bottom.append( - offset2_ex( - diff( - intersection(layerm_slices_surfaces, lower_layer->slices), // supported - lower_layer->get_region(region_id)->slices, - true - ), - -offs, offs - ), - stBottom - ); - } - } else { - // if no lower layer, all surfaces of this one are solid - // we clone surfaces because we're going to clear the slices collection - bottom = layerm.slices; - - // if we have raft layers, consider bottom layer as a bridge - // just like any other bottom surface lying on the void - const SurfaceType surface_type_bottom = - (this->config.raft_layers.value > 0 && this->config.support_material_contact_distance.value > 0) - ? stBottomBridge - : stBottom; - for (Surfaces::iterator it = bottom.surfaces.begin(); it != bottom.surfaces.end(); ++ it) - it->surface_type = surface_type_bottom; - } - - // now, if the object contained a thin membrane, we could have overlapping bottom - // and top surfaces; let's do an intersection to discover them and consider them - // as bottom surfaces (to allow for bridge detection) - if (!top.empty() && !bottom.empty()) { - const Polygons top_polygons = to_polygons(STDMOVE(top)); - top.clear(); - top.append( - offset2_ex(diff(top_polygons, bottom, true), -offs, offs), - stTop - ); - } - - // save surfaces to layer - layerm.slices.clear(); - layerm.slices.append(STDMOVE(top)); - layerm.slices.append(STDMOVE(bottom)); - - // find internal surfaces (difference between top/bottom surfaces and others) - { - Polygons topbottom = top; append_to(topbottom, (Polygons)bottom); - - layerm.slices.append( - offset2_ex( - diff(layerm_slices_surfaces, topbottom, true), - -offs, offs - ), - stInternal - ); - } - - #ifdef SLIC3R_DEBUG - printf(" layer %zu has %zu bottom, %zu top and %zu internal surfaces\n", - layerm.layer()->id(), bottom.size(), top.size(), - layerm.slices.size()-bottom.size()-top.size()); - #endif - - } // for each layer of a region - - /* Fill in layerm->fill_surfaces by trimming the layerm->slices by the cummulative layerm->fill_surfaces. - Note: this method should be idempotent, but fill_surfaces gets modified - in place. However we're now only using its boundaries (which are invariant) - so we're safe. This guarantees idempotence of prepare_infill() also in case - that combine_infill() turns some fill_surface into VOID surfaces. */ - FOREACH_LAYER(this, layer_it) { - LayerRegion &layerm = *(*layer_it)->get_region(region_id); - - const Polygons fill_boundaries = layerm.fill_surfaces; - layerm.fill_surfaces.clear(); - for (Surfaces::const_iterator surface = layerm.slices.surfaces.begin(); - surface != layerm.slices.surfaces.end(); ++ surface) { - layerm.fill_surfaces.append( - intersection_ex(*surface, fill_boundaries), - surface->surface_type - ); - } - } - } + parallelize( + std::queue(std::deque(this->layers.begin(), this->layers.end())), // cast LayerPtrs to std::queue + boost::bind(&Slic3r::Layer::detect_surfaces_type, _1), + this->_print->config.threads.value + ); } void From afacf0c99d2e26b29303ef6acef8cde8505ab4d4 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 9 Mar 2017 20:40:06 +0100 Subject: [PATCH 09/96] Parallelized process_external_surfaces --- xs/src/libslic3r/Layer.cpp | 7 +++++++ xs/src/libslic3r/Layer.hpp | 3 ++- xs/src/libslic3r/LayerRegion.cpp | 8 +++++--- xs/src/libslic3r/PrintObject.cpp | 16 +++++----------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/xs/src/libslic3r/Layer.cpp b/xs/src/libslic3r/Layer.cpp index 77bc74892..722b539e5 100644 --- a/xs/src/libslic3r/Layer.cpp +++ b/xs/src/libslic3r/Layer.cpp @@ -419,4 +419,11 @@ Layer::detect_surfaces_type() } } +void +Layer::process_external_surfaces() +{ + for (LayerRegion* &layerm : this->regions) + layerm->process_external_surfaces(); +} + } diff --git a/xs/src/libslic3r/Layer.hpp b/xs/src/libslic3r/Layer.hpp index 278927e15..29405258e 100644 --- a/xs/src/libslic3r/Layer.hpp +++ b/xs/src/libslic3r/Layer.hpp @@ -61,7 +61,7 @@ class LayerRegion void prepare_fill_surfaces(); void make_perimeters(const SurfaceCollection &slices, SurfaceCollection* fill_surfaces); void make_fill(); - void process_external_surfaces(const Layer* lower_layer); + void process_external_surfaces(); double infill_area_threshold() const; private: @@ -111,6 +111,7 @@ class Layer { void make_perimeters(); void make_fills(); void detect_surfaces_type(); + void process_external_surfaces(); protected: size_t _id; // sequential number of layer, 0-based diff --git a/xs/src/libslic3r/LayerRegion.cpp b/xs/src/libslic3r/LayerRegion.cpp index 42809d0ae..b7d9058fe 100644 --- a/xs/src/libslic3r/LayerRegion.cpp +++ b/xs/src/libslic3r/LayerRegion.cpp @@ -65,8 +65,10 @@ LayerRegion::make_perimeters(const SurfaceCollection &slices, SurfaceCollection* g.process(); } +// This function reads lower_layer->slices and writes this->bridged and this->fill_surfaces, +// so it's thread-safe. void -LayerRegion::process_external_surfaces(const Layer* lower_layer) +LayerRegion::process_external_surfaces() { const Surfaces &surfaces = this->fill_surfaces.surfaces; const double margin = scale_(EXTERNAL_INFILL_MARGIN); @@ -82,10 +84,10 @@ LayerRegion::process_external_surfaces(const Layer* lower_layer) also, supply the original expolygon instead of the grown one, because in case of very thin (but still working) anchors, the grown expolygon would go beyond them */ double angle = -1; - if (lower_layer != NULL && surface->is_bridge()) { + if (this->layer()->lower_layer != NULL && surface->is_bridge()) { BridgeDetector bd( surface->expolygon, - lower_layer->slices, + this->layer()->lower_layer->slices, this->flow(frInfill, true).scaled_width() ); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index be38fda0a..b8ab9cdbf 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -371,17 +371,11 @@ PrintObject::detect_surfaces_type() void PrintObject::process_external_surfaces() { - FOREACH_REGION(this->_print, region) { - size_t region_id = region - this->_print->regions.begin(); - - FOREACH_LAYER(this, layer_it) { - const Layer* lower_layer = (layer_it == this->layers.begin()) - ? NULL - : *(layer_it-1); - - (*layer_it)->get_region(region_id)->process_external_surfaces(lower_layer); - } - } + parallelize( + std::queue(std::deque(this->layers.begin(), this->layers.end())), // cast LayerPtrs to std::queue + boost::bind(&Slic3r::Layer::process_external_surfaces, _1), + this->_print->config.threads.value + ); } /* This method applies bridge flow to the first internal solid layer above From f1f14446378bae9b1387cc29dcc846853797cd70 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 9 Mar 2017 20:51:43 +0100 Subject: [PATCH 10/96] Put everything into try {} catch {} in GCodeSender::connect --- xs/src/libslic3r/GCodeSender.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/xs/src/libslic3r/GCodeSender.cpp b/xs/src/libslic3r/GCodeSender.cpp index 508bfe901..5fc33d9c9 100644 --- a/xs/src/libslic3r/GCodeSender.cpp +++ b/xs/src/libslic3r/GCodeSender.cpp @@ -46,30 +46,30 @@ bool GCodeSender::connect(std::string devname, unsigned int baud_rate) { this->disconnect(); - this->set_error_status(false); try { this->serial.open(devname); + + this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::odd)); + this->serial.set_option(asio::serial_port_base::character_size(asio::serial_port_base::character_size(8))); + this->serial.set_option(asio::serial_port_base::flow_control(asio::serial_port_base::flow_control::none)); + this->serial.set_option(asio::serial_port_base::stop_bits(asio::serial_port_base::stop_bits::one)); + this->set_baud_rate(baud_rate); + + this->serial.close(); + this->serial.open(devname); + this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::none)); + + // set baud rate again because set_option overwrote it + this->set_baud_rate(baud_rate); + this->open = true; + this->reset(); } catch (boost::system::system_error &e) { + printf("Caught error\n"); this->set_error_status(true); return false; } - this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::odd)); - this->serial.set_option(asio::serial_port_base::character_size(asio::serial_port_base::character_size(8))); - this->serial.set_option(asio::serial_port_base::flow_control(asio::serial_port_base::flow_control::none)); - this->serial.set_option(asio::serial_port_base::stop_bits(asio::serial_port_base::stop_bits::one)); - this->set_baud_rate(baud_rate); - - this->serial.close(); - this->serial.open(devname); - this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::none)); - - // set baud rate again because set_option overwrote it - this->set_baud_rate(baud_rate); - this->open = true; - this->reset(); - // a reset firmware expect line numbers to start again from 1 this->sent = 0; this->last_sent.clear(); From 28075264b8c25e4e2cddf9b35b4e77a5f547315b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 9 Mar 2017 21:24:45 +0100 Subject: [PATCH 11/96] Added manual control for temperature and bed temperature --- .../GUI/Controller/ManualControlDialog.pm | 48 ++++++++++++++++-- lib/Slic3r/GUI/Controller/PrinterPanel.pm | 2 +- lib/Slic3r/GUI/OptionsGroup.pm | 22 ++++++++ var/tick.png | Bin 0 -> 537 bytes 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100755 var/tick.png diff --git a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm index ac997730d..ea5a61f30 100644 --- a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm +++ b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm @@ -5,24 +5,29 @@ use strict; use warnings; use utf8; +use Scalar::Util qw(looks_like_number); use Slic3r::Geometry qw(PI X Y unscale); use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap wxBORDER_NONE wxTAB_TRAVERSAL); use Wx::Event qw(EVT_CLOSE EVT_BUTTON); use base qw(Wx::Dialog Class::Accessor); -__PACKAGE__->mk_accessors(qw(sender config2 x_homed y_homed)); +__PACKAGE__->mk_accessors(qw(sender writer config2 x_homed y_homed)); sub new { my ($class, $parent, $config, $sender) = @_; my $self = $class->SUPER::new($parent, -1, "Manual Control", wxDefaultPosition, - [500,380], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); + [500,400], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); $self->sender($sender); + $self->writer(Slic3r::GCode::Writer->new); + $self->writer->config->apply_dynamic($config); $self->config2({ xy_travel_speed => 130, z_travel_speed => 10, + temperature => '', + bed_temperature => '', }); my $bed_sizer = Wx::FlexGridSizer->new(2, 3, 1, 1); @@ -133,7 +138,44 @@ sub new { )); $optgroup->append_line($line); } - + { + my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'temperature', + type => 's', + label => 'Temperature', + default => '', + sidetext => '°C', + default => $self->config2->{temperature}, + )); + $line->append_button("Set", "tick.png", sub { + if (!looks_like_number($self->config2->{temperature})) { + Slic3r::GUI::show_error($self, "Invalid temperature."); + return; + } + my $cmd = $self->writer->set_temperature($self->config2->{temperature}); + $self->sender->send($cmd, 1); + }); + $optgroup->append_line($line); + } + { + my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'bed_temperature', + type => 's', + label => 'Bed Temperature', + default => '', + sidetext => '°C', + default => $self->config2->{bed_temperature}, + )); + $line->append_button("Set", "tick.png", sub { + if (!looks_like_number($self->config2->{bed_temperature})) { + Slic3r::GUI::show_error($self, "Invalid bed temperature."); + return; + } + my $cmd = $self->writer->set_bed_temperature($self->config2->{bed_temperature}); + $self->sender->send($cmd, 1); + }); + $optgroup->append_line($line); + } my $main_sizer = Wx::BoxSizer->new(wxVERTICAL); $main_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10); $main_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); diff --git a/lib/Slic3r/GUI/Controller/PrinterPanel.pm b/lib/Slic3r/GUI/Controller/PrinterPanel.pm index fa5910a14..6fbabf15a 100644 --- a/lib/Slic3r/GUI/Controller/PrinterPanel.pm +++ b/lib/Slic3r/GUI/Controller/PrinterPanel.pm @@ -279,7 +279,7 @@ sub _update_connection_controls { $self->{btn_manual_control}->Hide; $self->{btn_manual_control}->Disable; - if ($self->is_connected) { + if ($self->is_connected || 1) { $self->{btn_connect}->Hide; $self->{btn_manual_control}->Show; if (!$self->printing || $self->printing->paused) { diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index e1428c8ea..bbf3e8bd2 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -282,6 +282,9 @@ has 'widget' => (is => 'rw'); has '_options' => (is => 'ro', default => sub { [] }); has '_extra_widgets' => (is => 'ro', default => sub { [] }); +use Wx qw(:button :misc :bitmap); +use Wx::Event qw(EVT_BUTTON); + # this method accepts a Slic3r::GUI::OptionsGroup::Option object sub append_option { my ($self, $option) = @_; @@ -293,6 +296,25 @@ sub append_widget { push @{$self->_extra_widgets}, $widget; } +sub append_button { + my ($self, $text, $icon, $cb, $ref) = @_; + + $self->append_widget(sub { + my ($parent) = @_; + + my $btn = Wx::Button->new($parent, -1, + $text, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); + $btn->SetFont($Slic3r::GUI::small_font); + if ($Slic3r::GUI::have_button_icons) { + $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG)); + } + $$ref = $btn if $ref; + + EVT_BUTTON($parent, $btn, $cb); + return $btn; + }); +} + sub get_options { my ($self) = @_; return [ @{$self->_options} ]; diff --git a/var/tick.png b/var/tick.png new file mode 100755 index 0000000000000000000000000000000000000000..a9925a06ab02db30c1e7ead9c701c15bc63145cb GIT binary patch literal 537 zcmV+!0_OdRP)Hs{AQG2a)rMyf zFQK~pm1x3+7!nu%-M`k}``c>^00{o_1pjWJUTfl8mg=3qGEl8H@}^@w`VUx0_$uy4 z2FhRqKX}xI*?Tv1DJd8z#F#0c%*~rM30HE1@2o5m~}ZyoWhqv>ql{V z1ZGE0lgcoK^lx+eqc*rAX1Ky;Xx3U%u#zG!m-;eD1Qsn@kf3|F9qz~|95=&g3(7!X zB}JAT>RU;a%vaNOGnJ%e1=K6eAh43c(QN8RQ6~GP%O}Jju$~Ld*%`mO1p Date: Thu, 9 Mar 2017 21:35:17 +0100 Subject: [PATCH 12/96] Refactoring, use the new OptionsGroup::append_button() instead of append_widget() --- lib/Slic3r/GUI/OptionsGroup.pm | 3 +- lib/Slic3r/GUI/Projector.pm | 37 +++---- lib/Slic3r/GUI/Tab.pm | 181 +++++++++++---------------------- 3 files changed, 73 insertions(+), 148 deletions(-) diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index bbf3e8bd2..fac5394f8 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -297,7 +297,7 @@ sub append_widget { } sub append_button { - my ($self, $text, $icon, $cb, $ref) = @_; + my ($self, $text, $icon, $cb, $ref, $disable) = @_; $self->append_widget(sub { my ($parent) = @_; @@ -308,6 +308,7 @@ sub append_button { if ($Slic3r::GUI::have_button_icons) { $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG)); } + $btn->Disable if $disable; $$ref = $btn if $ref; EVT_BUTTON($parent, $btn, $cb); diff --git a/lib/Slic3r/GUI/Projector.pm b/lib/Slic3r/GUI/Projector.pm index b6d1cb5a6..9023cb0c7 100644 --- a/lib/Slic3r/GUI/Projector.pm +++ b/lib/Slic3r/GUI/Projector.pm @@ -74,33 +74,20 @@ sub new { return $btn; }); - my $serial_test = sub { - my ($parent) = @_; - - my $btn = $self->{serial_test_btn} = Wx::Button->new($parent, -1, - "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - if ($Slic3r::GUI::have_button_icons) { - $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("wrench.png"), wxBITMAP_TYPE_PNG)); - } - - EVT_BUTTON($self, $btn, sub { - my $sender = Slic3r::GCode::Sender->new; - my $res = $sender->connect( - $self->{config}->serial_port, - $self->{config}->serial_speed, - ); - if ($res && $sender->wait_connected) { - Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!"); - } else { - Slic3r::GUI::show_error($self, "Connection failed."); - } - }); - return $btn; - }; $line->append_option($serial_port); $line->append_option($optgroup->get_option('serial_speed')); - $line->append_widget($serial_test); + $line->append_button("Test", "wrench.png", sub { + my $sender = Slic3r::GCode::Sender->new; + my $res = $sender->connect( + $self->{config}->serial_port, + $self->{config}->serial_speed, + ); + if ($res && $sender->wait_connected) { + Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!"); + } else { + Slic3r::GUI::show_error($self, "Connection failed."); + } + }, \$self->{serial_test_btn}); $optgroup->append_line($line); } } diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index b813e99d0..fdd05b75b 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -1068,32 +1068,6 @@ sub build { )); $self->{config}->set('printer_settings_id', ''); - my $bed_shape_widget = sub { - my ($parent) = @_; - - my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize, - wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - if ($Slic3r::GUI::have_button_icons) { - $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG)); - } - - my $sizer = Wx::BoxSizer->new(wxHORIZONTAL); - $sizer->Add($btn); - - EVT_BUTTON($self, $btn, sub { - my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape); - if ($dlg->ShowModal == wxID_OK) { - my $value = $dlg->GetValue; - $self->{config}->set('bed_shape', $value); - $self->update_dirty; - $self->_on_value_change('bed_shape', $value); - } - }); - - return $sizer; - }; - $self->{extruders_count} = 1; { @@ -1102,9 +1076,17 @@ sub build { my $optgroup = $page->new_optgroup('Size and coordinates'); my $line = Slic3r::GUI::OptionsGroup::Line->new( - label => 'Bed shape', - widget => $bed_shape_widget, + label => 'Bed shape', ); + $line->append_button("Set…", "cog.png", sub { + my $dlg = Slic3r::GUI::BedShapeDialog->new($self, $self->{config}->bed_shape); + if ($dlg->ShowModal == wxID_OK) { + my $value = $dlg->GetValue; + $self->{config}->set('bed_shape', $value); + $self->update_dirty; + $self->_on_value_change('bed_shape', $value); + } + }); $optgroup->append_line($line); $optgroup->append_single_option_line('z_offset'); @@ -1151,108 +1133,63 @@ sub build { return $btn; }); - my $serial_test = sub { - my ($parent) = @_; - - my $btn = $self->{serial_test_btn} = Wx::Button->new($parent, -1, - "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - if ($Slic3r::GUI::have_button_icons) { - $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("wrench.png"), wxBITMAP_TYPE_PNG)); - } - - EVT_BUTTON($self, $btn, sub { - my $sender = Slic3r::GCode::Sender->new; - my $res = $sender->connect( - $self->{config}->serial_port, - $self->{config}->serial_speed, - ); - if ($res && $sender->wait_connected) { - Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!"); - } else { - Slic3r::GUI::show_error($self, "Connection failed."); - } - }); - return $btn; - }; $line->append_option($serial_port); $line->append_option($optgroup->get_option('serial_speed')); - $line->append_widget($serial_test); + $line->append_button("Test", "wrench.png", sub { + my $sender = Slic3r::GCode::Sender->new; + my $res = $sender->connect( + $self->{config}->serial_port, + $self->{config}->serial_speed, + ); + if ($res && $sender->wait_connected) { + Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!"); + } else { + Slic3r::GUI::show_error($self, "Connection failed."); + } + }, \$self->{serial_test_btn}); $optgroup->append_line($line); } { my $optgroup = $page->new_optgroup('OctoPrint upload'); - # append two buttons to the Host line - my $octoprint_host_browse = sub { - my ($parent) = @_; - - my $btn = Wx::Button->new($parent, -1, "Browse…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT); - $btn->SetFont($Slic3r::GUI::small_font); - if ($Slic3r::GUI::have_button_icons) { - $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("zoom.png"), wxBITMAP_TYPE_PNG)); - } - - if (!eval "use Net::Bonjour; 1") { - $btn->Disable; - } - - EVT_BUTTON($self, $btn, sub { - # look for devices - my $entries; - { - my $res = Net::Bonjour->new('http'); - $res->discover; - $entries = [ $res->entries ]; - } - if (@{$entries}) { - my $dlg = Slic3r::GUI::BonjourBrowser->new($self, $entries); - if ($dlg->ShowModal == wxID_OK) { - my $value = $dlg->GetValue . ":" . $dlg->GetPort; - $self->{config}->set('octoprint_host', $value); - $self->update_dirty; - $self->_on_value_change('octoprint_host', $value); - $self->reload_config; - } - } else { - Wx::MessageDialog->new($self, 'No Bonjour device found', 'Device Browser', wxOK | wxICON_INFORMATION)->ShowModal; - } - }); - - return $btn; - }; - my $octoprint_host_test = sub { - my ($parent) = @_; - - my $btn = $self->{octoprint_host_test_btn} = Wx::Button->new($parent, -1, - "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - $btn->SetFont($Slic3r::GUI::small_font); - if ($Slic3r::GUI::have_button_icons) { - $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("wrench.png"), wxBITMAP_TYPE_PNG)); - } - - EVT_BUTTON($self, $btn, sub { - my $ua = LWP::UserAgent->new; - $ua->timeout(10); - - my $res = $ua->get( - "http://" . $self->{config}->octoprint_host . "/api/version", - 'X-Api-Key' => $self->{config}->octoprint_apikey, - ); - if ($res->is_success) { - Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!"); - } else { - Slic3r::GUI::show_error($self, - "I wasn't able to connect to OctoPrint (" . $res->status_line . "). " - . "Check hostname and OctoPrint version (at least 1.1.0 is required)."); - } - }); - return $btn; - }; - my $host_line = $optgroup->create_single_option_line('octoprint_host'); - $host_line->append_widget($octoprint_host_browse); - $host_line->append_widget($octoprint_host_test); + $host_line->append_button("Browse…", "zoom.png", sub { + # look for devices + my $entries; + { + my $res = Net::Bonjour->new('http'); + $res->discover; + $entries = [ $res->entries ]; + } + if (@{$entries}) { + my $dlg = Slic3r::GUI::BonjourBrowser->new($self, $entries); + if ($dlg->ShowModal == wxID_OK) { + my $value = $dlg->GetValue . ":" . $dlg->GetPort; + $self->{config}->set('octoprint_host', $value); + $self->update_dirty; + $self->_on_value_change('octoprint_host', $value); + $self->reload_config; + } + } else { + Wx::MessageDialog->new($self, 'No Bonjour device found', 'Device Browser', wxOK | wxICON_INFORMATION)->ShowModal; + } + }, undef, !eval "use Net::Bonjour; 1"); + $host_line->append_button("Test", "wrench.png", sub { + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + + my $res = $ua->get( + "http://" . $self->{config}->octoprint_host . "/api/version", + 'X-Api-Key' => $self->{config}->octoprint_apikey, + ); + if ($res->is_success) { + Slic3r::GUI::show_info($self, "Connection to OctoPrint works correctly.", "Success!"); + } else { + Slic3r::GUI::show_error($self, + "I wasn't able to connect to OctoPrint (" . $res->status_line . "). " + . "Check hostname and OctoPrint version (at least 1.1.0 is required)."); + } + }, \$self->{octoprint_host_test_btn}); $optgroup->append_line($host_line); $optgroup->append_single_option_line('octoprint_apikey'); } From 6d371884a19a7ef859b0f77df9a0f3333c798c9a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 9 Mar 2017 21:37:56 +0100 Subject: [PATCH 13/96] Remember manual control settings --- lib/Slic3r/GUI/Controller/ManualControlDialog.pm | 9 ++------- lib/Slic3r/GUI/Controller/PrinterPanel.pm | 10 ++++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm index ea5a61f30..ca6ff1737 100644 --- a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm +++ b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm @@ -15,7 +15,7 @@ use base qw(Wx::Dialog Class::Accessor); __PACKAGE__->mk_accessors(qw(sender writer config2 x_homed y_homed)); sub new { - my ($class, $parent, $config, $sender) = @_; + my ($class, $parent, $config, $sender, $manual_control_config) = @_; my $self = $class->SUPER::new($parent, -1, "Manual Control", wxDefaultPosition, [500,400], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); @@ -23,12 +23,7 @@ sub new { $self->writer(Slic3r::GCode::Writer->new); $self->writer->config->apply_dynamic($config); - $self->config2({ - xy_travel_speed => 130, - z_travel_speed => 10, - temperature => '', - bed_temperature => '', - }); + $self->config2($manual_control_config); my $bed_sizer = Wx::FlexGridSizer->new(2, 3, 1, 1); $bed_sizer->AddGrowableCol(1, 1); diff --git a/lib/Slic3r/GUI/Controller/PrinterPanel.pm b/lib/Slic3r/GUI/Controller/PrinterPanel.pm index 6fbabf15a..7cfe9fc59 100644 --- a/lib/Slic3r/GUI/Controller/PrinterPanel.pm +++ b/lib/Slic3r/GUI/Controller/PrinterPanel.pm @@ -9,7 +9,7 @@ use Wx::Event qw(EVT_BUTTON EVT_MOUSEWHEEL EVT_TIMER EVT_SCROLLWIN); use base qw(Wx::Panel Class::Accessor); __PACKAGE__->mk_accessors(qw(printer_name config sender jobs - printing status_timer temp_timer)); + printing status_timer temp_timer manual_control_config)); use constant CONNECTION_TIMEOUT => 3; # seconds use constant STATUS_TIMER_INTERVAL => 1000; # milliseconds @@ -21,6 +21,12 @@ sub new { $self->printer_name($printer_name || 'Printer'); $self->config($config); + $self->manual_control_config({ + xy_travel_speed => 130, + z_travel_speed => 10, + temperature => '', + bed_temperature => '', + }); $self->jobs([]); # set up the timer that polls for updates @@ -171,7 +177,7 @@ sub new { $left_sizer->Add($btn, 0, wxTOP, 15); EVT_BUTTON($self, $btn, sub { my $dlg = Slic3r::GUI::Controller::ManualControlDialog->new - ($self, $self->config, $self->sender); + ($self, $self->config, $self->sender, $self->manual_control_config); $dlg->ShowModal; }); } From f018c20a6d9d6384aeb5eaada80a12a9bf416f5c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 11 Mar 2017 00:06:23 +0100 Subject: [PATCH 14/96] Console for sending manual commands in manual printer control --- .../GUI/Controller/ManualControlDialog.pm | 136 ++++++++++++------ lib/Slic3r/GUI/Controller/PrinterPanel.pm | 7 +- 2 files changed, 100 insertions(+), 43 deletions(-) diff --git a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm index ca6ff1737..224c5e069 100644 --- a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm +++ b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm @@ -7,7 +7,7 @@ use utf8; use Scalar::Util qw(looks_like_number); use Slic3r::Geometry qw(PI X Y unscale); -use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap +use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap :textctrl wxBORDER_NONE wxTAB_TRAVERSAL); use Wx::Event qw(EVT_CLOSE EVT_BUTTON); use base qw(Wx::Dialog Class::Accessor); @@ -107,7 +107,7 @@ sub new { my $optgroup = Slic3r::GUI::OptionsGroup->new( parent => $self, - title => 'Settings', + title => 'Manual motion settings', on_change => sub { my ($opt_id, $value) = @_; $self->config2->{$opt_id} = $value; @@ -133,53 +133,101 @@ sub new { )); $optgroup->append_line($line); } + my $left_sizer = Wx::BoxSizer->new(wxVERTICAL); + $left_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10); + $left_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); + + my $right_sizer = Wx::BoxSizer->new(wxVERTICAL); { - my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( - opt_id => 'temperature', - type => 's', - label => 'Temperature', - default => '', - sidetext => '°C', - default => $self->config2->{temperature}, - )); - $line->append_button("Set", "tick.png", sub { - if (!looks_like_number($self->config2->{temperature})) { - Slic3r::GUI::show_error($self, "Invalid temperature."); - return; - } - my $cmd = $self->writer->set_temperature($self->config2->{temperature}); - $self->sender->send($cmd, 1); - }); - $optgroup->append_line($line); + my $optgroup = Slic3r::GUI::OptionsGroup->new( + parent => $self, + title => 'Temperature', + on_change => sub { + my ($opt_id, $value) = @_; + $self->config2->{$opt_id} = $value; + }, + ); + $right_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); + { + my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'temperature', + type => 's', + label => 'Extruder', + default => '', + sidetext => '°C', + default => $self->config2->{temperature}, + )); + $line->append_button("Set", "tick.png", sub { + if (!looks_like_number($self->config2->{temperature})) { + Slic3r::GUI::show_error($self, "Invalid temperature."); + return; + } + my $cmd = $self->writer->set_temperature($self->config2->{temperature}); + $self->sender->send($cmd, 1); + }); + $optgroup->append_line($line); + } + { + my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'bed_temperature', + type => 's', + label => 'Bed', + default => '', + sidetext => '°C', + default => $self->config2->{bed_temperature}, + )); + $line->append_button("Set", "tick.png", sub { + if (!looks_like_number($self->config2->{bed_temperature})) { + Slic3r::GUI::show_error($self, "Invalid bed temperature."); + return; + } + my $cmd = $self->writer->set_bed_temperature($self->config2->{bed_temperature}); + $self->sender->send($cmd, 1); + }); + $optgroup->append_line($line); + } } + { - my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( - opt_id => 'bed_temperature', - type => 's', - label => 'Bed Temperature', - default => '', - sidetext => '°C', - default => $self->config2->{bed_temperature}, - )); - $line->append_button("Set", "tick.png", sub { - if (!looks_like_number($self->config2->{bed_temperature})) { - Slic3r::GUI::show_error($self, "Invalid bed temperature."); - return; - } - my $cmd = $self->writer->set_bed_temperature($self->config2->{bed_temperature}); - $self->sender->send($cmd, 1); + my $box = Wx::StaticBox->new($self, -1, "Console"); + my $sbsizer = Wx::StaticBoxSizer->new($box, wxVERTICAL); + $right_sizer->Add($sbsizer, 1, wxEXPAND, 0); + + my $log = $self->{log_textctrl} = Wx::TextCtrl->new($box, -1, "", wxDefaultPosition, wxDefaultSize, + wxTE_MULTILINE | wxBORDER_NONE); + $log->SetBackgroundColour($box->GetBackgroundColour); + $log->SetFont($Slic3r::GUI::small_font); + $log->SetEditable(0); + $sbsizer->Add($self->{log_textctrl}, 1, wxEXPAND, 0); + + my $cmd_sizer = Wx::BoxSizer->new(wxHORIZONTAL); + my $cmd_textctrl = Wx::TextCtrl->new($box, -1, ''); + $cmd_sizer->Add($cmd_textctrl, 1, wxEXPAND, 0); + + my $btn = Wx::Button->new($box, -1, + "Send", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); + $btn->SetFont($Slic3r::GUI::small_font); + if ($Slic3r::GUI::have_button_icons) { + $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("cog_go.png"), wxBITMAP_TYPE_PNG)); + } + $cmd_sizer->Add($btn, 0, wxEXPAND | wxLEFT, 5); + + EVT_BUTTON($box, $btn, sub { + return if $cmd_textctrl->GetValue eq ''; + $self->sender->send($cmd_textctrl->GetValue, 1); + $cmd_textctrl->SetValue(''); }); - $optgroup->append_line($line); + + $sbsizer->Add($cmd_sizer, 0, wxEXPAND | wxTOP, 2); } - my $main_sizer = Wx::BoxSizer->new(wxVERTICAL); - $main_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10); - $main_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); - #$main_sizer->Add($self->CreateButtonSizer(wxCLOSE), 0, wxEXPAND); - #EVT_BUTTON($self, wxID_CLOSE, sub { $self->Close }); + + my $main_sizer = Wx::BoxSizer->new(wxHORIZONTAL); + $main_sizer->Add($left_sizer, 1, wxEXPAND | wxRIGHT, 10); + $main_sizer->Add($right_sizer, 0, wxEXPAND, 0); $self->SetSizer($main_sizer); $self->SetMinSize($self->GetSize); - #$main_sizer->SetSizeHints($self); + $main_sizer->SetSizeHints($self); $self->Layout; # needed to actually free memory @@ -191,6 +239,12 @@ sub new { return $self; } +sub update_log { + my ($self, $log) = @_; + + $self->{log_textctrl}->SetValue($log); +} + sub abs_xy_move { my ($self, $pos) = @_; diff --git a/lib/Slic3r/GUI/Controller/PrinterPanel.pm b/lib/Slic3r/GUI/Controller/PrinterPanel.pm index 7cfe9fc59..3f5fbf9c1 100644 --- a/lib/Slic3r/GUI/Controller/PrinterPanel.pm +++ b/lib/Slic3r/GUI/Controller/PrinterPanel.pm @@ -44,6 +44,8 @@ sub new { } } $self->{log_textctrl}->AppendText("$_\n") for @{$self->sender->purge_log}; + $self->{manual_control_dialog}->update_log($self->{log_textctrl}->GetValue) + if $self->{manual_control_dialog}; { my $temp = $self->sender->getT; if ($temp eq '') { @@ -176,9 +178,10 @@ sub new { $btn->Hide; $left_sizer->Add($btn, 0, wxTOP, 15); EVT_BUTTON($self, $btn, sub { - my $dlg = Slic3r::GUI::Controller::ManualControlDialog->new + $self->{manual_control_dialog} = my $dlg = Slic3r::GUI::Controller::ManualControlDialog->new ($self, $self->config, $self->sender, $self->manual_control_config); $dlg->ShowModal; + undef $self->{manual_control_dialog}; }); } @@ -285,7 +288,7 @@ sub _update_connection_controls { $self->{btn_manual_control}->Hide; $self->{btn_manual_control}->Disable; - if ($self->is_connected || 1) { + if ($self->is_connected) { $self->{btn_connect}->Hide; $self->{btn_manual_control}->Show; if (!$self->printing || $self->printing->paused) { From 0741ecc2aa4b00629f210a6348d56adcfb237bf8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 10 Mar 2017 17:36:14 -0600 Subject: [PATCH 15/96] Add weight/cost output to gcode. On the way to #647 (#3669) * Add weight/cost output to gcode. On the way to #647 * added total cost/weight to Extruder statistics, mocked up addendum to status bar change. * Added second information box that populates after exporting gcode for sliced statistics. * Changed filament density to use g/cm^3. Extended tooltip to indicate calculation methods. * Hide sliced info box when gcode export hasn't been done. * Remove if invalidated and we have background processing or the configuration changes. * Called layout after every Hide/Show call to ensure that it is placed correctly on different platforms. Changed output units to cm/cm^3 Conflicts: lib/Slic3r/GUI/Plater.pm --- lib/Slic3r/GUI/Plater.pm | 54 +++++++++++++++++++++++++++++++- lib/Slic3r/GUI/Tab.pm | 4 ++- lib/Slic3r/Print/GCode.pm | 16 ++++++++++ lib/Slic3r/Print/Object.pm | 2 ++ xs/src/libslic3r/Extruder.cpp | 12 +++++++ xs/src/libslic3r/Extruder.hpp | 2 ++ xs/src/libslic3r/Print.hpp | 2 +- xs/src/libslic3r/PrintConfig.cpp | 24 ++++++++++++++ xs/src/libslic3r/PrintConfig.hpp | 4 +++ xs/xsp/Extruder.xsp | 2 ++ xs/xsp/Print.xsp | 21 +++++++++++++ 11 files changed, 140 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index fa04fc436..3ce193a7c 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -142,6 +142,7 @@ sub new { $self->stop_background_process; $self->statusbar->SetStatusText("Slicing cancelled"); $self->{preview_notebook}->SetSelection(0); + }); $self->start_background_process; } else { @@ -431,6 +432,36 @@ sub new { } } } + + my $print_info_sizer; + { + my $box = Wx::StaticBox->new($self, -1, "Sliced Info"); + $print_info_sizer = Wx::StaticBoxSizer->new($box, wxVERTICAL); + $print_info_sizer->SetMinSize([350,-1]); + my $grid_sizer = Wx::FlexGridSizer->new(2, 2, 5, 5); + $grid_sizer->SetFlexibleDirection(wxHORIZONTAL); + $grid_sizer->AddGrowableCol(1, 1); + $grid_sizer->AddGrowableCol(3, 1); + $print_info_sizer->Add($grid_sizer, 0, wxEXPAND); + my @info = ( + fil_cm => "Used Filament (cm)", + fil_cm3 => "Used Filament (cm^3)", + fil_g => "Used Filament (g)", + cost => "Cost", + ); + while (my $field = shift @info) { + my $label = shift @info; + my $text = Wx::StaticText->new($self, -1, "$label:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); + $text->SetFont($Slic3r::GUI::small_font); + $grid_sizer->Add($text, 0); + + $self->{"print_info_$field"} = Wx::StaticText->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + $self->{"print_info_$field"}->SetFont($Slic3r::GUI::small_font); + $grid_sizer->Add($self->{"print_info_$field"}, 0); + } + $self->{"sliced_info_box"} = $print_info_sizer; + + } my $buttons_sizer = Wx::BoxSizer->new(wxHORIZONTAL); $buttons_sizer->AddStretchSpacer(1); @@ -444,6 +475,9 @@ sub new { $right_sizer->Add($buttons_sizer, 0, wxEXPAND | wxBOTTOM, 5); $right_sizer->Add($self->{list}, 1, wxEXPAND, 5); $right_sizer->Add($object_info_sizer, 0, wxEXPAND, 0); + $right_sizer->Add($print_info_sizer, 0, wxEXPAND, 0); + $right_sizer->Hide($print_info_sizer); + $self->{"right_sizer"} = $right_sizer; my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL); $hsizer->Add($self->{preview_notebook}, 1, wxEXPAND | wxTOP, 1); @@ -1090,6 +1124,11 @@ sub async_apply_config { if ($invalidated) { # kill current thread if any $self->stop_background_process; + # remove the sliced statistics box because something changed. + if ($self->{"right_sizer"}) { + $self->{"right_sizer"}->Hide($self->{"sliced_info_box"}); + $self->{"right_sizer"}->Layout; + } } else { $self->resume_background_process; } @@ -1263,6 +1302,8 @@ sub export_gcode { # this updates buttons status $self->object_list_changed; + $self->{"right_sizer"}->Show($self->{"sliced_info_box"}); + $self->{"right_sizer"}->Layout; return $self->{export_gcode_output_file}; } @@ -1357,6 +1398,10 @@ sub on_export_completed { $self->send_gcode if $send_gcode; $self->{print_file} = undef; $self->{send_gcode_file} = undef; + $self->{"print_info_cost"}->SetLabel(sprintf("%.2f" , $self->{print}->total_cost)); + $self->{"print_info_fil_g"}->SetLabel(sprintf("%.2f" , $self->{print}->total_weight)); + $self->{"print_info_fil_cm3"}->SetLabel(sprintf("%.2f" , $self->{print}->total_extruded_volume) / 1000); + $self->{"print_info_fil_cm"}->SetLabel(sprintf("%.2f" , $self->{print}->total_used_filament) / 10); # this updates buttons status $self->object_list_changed; @@ -1553,7 +1598,10 @@ sub update { } else { $self->resume_background_process; } - + if ($self->{"right_sizer"}) { + $self->{"right_sizer"}->Hide($self->{"sliced_info_box"}); + $self->{"right_sizer"}->Layout; + } $self->refresh_canvases; } @@ -1627,6 +1675,10 @@ sub on_config_change { $self->Layout; } } + if ($self->{"right_sizer"}) { + $self->{"right_sizer"}->Hide($self->{"sliced_info_box"}); + $self->{"right_sizer"}->Layout; + } return if !$self->GetFrame->is_loaded; diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index fdd05b75b..c515df76f 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -897,7 +897,7 @@ sub build { my $self = shift; $self->init_config_options(qw( - filament_colour filament_diameter filament_notes filament_max_volumetric_speed extrusion_multiplier + filament_colour filament_diameter filament_notes filament_max_volumetric_speed extrusion_multiplier filament_density filament_cost temperature first_layer_temperature bed_temperature first_layer_bed_temperature fan_always_on cooling min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers @@ -912,6 +912,8 @@ sub build { $optgroup->append_single_option_line('filament_colour', 0); $optgroup->append_single_option_line('filament_diameter', 0); $optgroup->append_single_option_line('extrusion_multiplier', 0); + $optgroup->append_single_option_line('filament_density', 0); + $optgroup->append_single_option_line('filament_cost', 0); } { diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 026865392..086f7e33f 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -255,17 +255,33 @@ sub export { $self->print->clear_filament_stats; $self->print->total_used_filament(0); $self->print->total_extruded_volume(0); + $self->print->total_weight(0); + $self->print->total_cost(0); foreach my $extruder (@{$gcodegen->writer->extruders}) { my $used_filament = $extruder->used_filament; my $extruded_volume = $extruder->extruded_volume; + my $filament_weight = $extruded_volume * $extruder->filament_density / 1000; + my $filament_cost = $filament_weight * ($extruder->filament_cost / 1000); $self->print->set_filament_stats($extruder->id, $used_filament); printf $fh "; filament used = %.1fmm (%.1fcm3)\n", $used_filament, $extruded_volume/1000; + if ($filament_weight > 0) { + $self->print->total_weight($self->print->total_weight + $filament_weight); + printf $fh "; filament used = %.1fg\n", + $filament_weight; + if ($filament_cost > 0) { + $self->print->total_cost($self->print->total_cost + $filament_cost); + printf $fh "; filament cost = %.1f\n", + $filament_cost; + } + } $self->print->total_used_filament($self->print->total_used_filament + $used_filament); $self->print->total_extruded_volume($self->print->total_extruded_volume + $extruded_volume); } + printf $fh "; total filament cost = %.1f\n", + $self->print->total_cost; # append full config print $fh "\n"; diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 9b9e99e9f..8dbefc117 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -417,6 +417,8 @@ sub generate_support_material { $self->_support_material->generate($self); $self->set_step_done(STEP_SUPPORTMATERIAL); + my $stats = "Weight: %.1fg, Cost: %.1f" , $self->print->total_weight, $self->print->total_cost; + $self->print->status_cb->(85, $stats); } sub _support_material { diff --git a/xs/src/libslic3r/Extruder.cpp b/xs/src/libslic3r/Extruder.cpp index b9be14661..8cf3e8b0a 100644 --- a/xs/src/libslic3r/Extruder.cpp +++ b/xs/src/libslic3r/Extruder.cpp @@ -111,6 +111,18 @@ Extruder::filament_diameter() const return this->config->filament_diameter.get_at(this->id); } +double +Extruder::filament_density() const +{ + return this->config->filament_density.get_at(this->id); +} + +double +Extruder::filament_cost() const +{ + return this->config->filament_cost.get_at(this->id); +} + double Extruder::extrusion_multiplier() const { diff --git a/xs/src/libslic3r/Extruder.hpp b/xs/src/libslic3r/Extruder.hpp index 76b70df63..729996cd1 100644 --- a/xs/src/libslic3r/Extruder.hpp +++ b/xs/src/libslic3r/Extruder.hpp @@ -29,6 +29,8 @@ class Extruder double used_filament() const; double filament_diameter() const; + double filament_density() const; + double filament_cost() const; double extrusion_multiplier() const; double retract_length() const; double retract_lift() const; diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 5ec3653ed..092fc84c3 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -167,7 +167,7 @@ class Print PrintRegionPtrs regions; PlaceholderParser placeholder_parser; // TODO: status_cb - double total_used_filament, total_extruded_volume; + double total_used_filament, total_extruded_volume, total_cost, total_weight; std::map filament_stats; PrintState state; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 34a10a414..aca51e334 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -355,6 +355,30 @@ PrintConfigDef::PrintConfigDef() opt->values.push_back(3); def->default_value = opt; } + + def = this->add("filament_density", coFloats); + def->label = "Density"; + def->tooltip = "Enter your filament density here. This is only for statistical information. A decent way is to weigh a known length of filament and compute the ratio of the length to volume. Better is to calculate the volume directly through displacement."; + def->sidetext = "g/cm^3"; + def->cli = "filament-density=f@"; + def->min = 0; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0); + def->default_value = opt; + } + + def = this->add("filament_cost", coFloats); + def->label = "Cost"; + def->tooltip = "Enter your filament cost per kg here. This is only for statistical information."; + def->sidetext = "money/kg"; + def->cli = "filament-cost=f@"; + def->min = 0; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0); + def->default_value = opt; + } def = this->add("filament_settings_id", coString); def->default_value = new ConfigOptionString(""); diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 2a0b080bf..27c5d4e75 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -289,6 +289,8 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionString extrusion_axis; ConfigOptionFloats extrusion_multiplier; ConfigOptionFloats filament_diameter; + ConfigOptionFloats filament_density; + ConfigOptionFloats filament_cost; ConfigOptionFloats filament_max_volumetric_speed; ConfigOptionBool gcode_comments; ConfigOptionEnum gcode_flavor; @@ -322,6 +324,8 @@ class GCodeConfig : public virtual StaticPrintConfig OPT_PTR(extrusion_axis); OPT_PTR(extrusion_multiplier); OPT_PTR(filament_diameter); + OPT_PTR(filament_density); + OPT_PTR(filament_cost); OPT_PTR(filament_max_volumetric_speed); OPT_PTR(gcode_comments); OPT_PTR(gcode_flavor); diff --git a/xs/xsp/Extruder.xsp b/xs/xsp/Extruder.xsp index 2a315858e..36f5427c7 100644 --- a/xs/xsp/Extruder.xsp +++ b/xs/xsp/Extruder.xsp @@ -42,6 +42,8 @@ %code%{ RETVAL = THIS->retract_speed_mm_min; %}; double filament_diameter(); + double filament_density(); + double filament_cost(); double extrusion_multiplier(); double retract_length(); double retract_lift(); diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index fbd4c3765..1bd25edb4 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -288,5 +288,26 @@ Print::total_extruded_volume(...) OUTPUT: RETVAL + +double +Print::total_weight(...) + CODE: + if (items > 1) { + THIS->total_weight = (double)SvNV(ST(1)); + } + RETVAL = THIS->total_weight; + OUTPUT: + RETVAL + +double +Print::total_cost(...) + CODE: + if (items > 1) { + THIS->total_cost = (double)SvNV(ST(1)); + } + RETVAL = THIS->total_cost; + OUTPUT: + RETVAL + %} }; From 25bcff3656c911e26904e7cf846aefb2a4eaa5b4 Mon Sep 17 00:00:00 2001 From: Len Trigg Date: Sat, 11 Mar 2017 18:37:17 +1300 Subject: [PATCH 16/96] Fix #2861, provide consistent mouse-wheel zoom direction, plus a GUI preference to invert (#3749) * Make mouse-wheel in 2D toolpath zoom in the same direction as it does in 3D and 3D-preview * Add a GUI preference setting for whether to invert the direction that mouse-wheel scrolling will zoom in the 2D and 3D panels. --- lib/Slic3r/GUI.pm | 2 ++ lib/Slic3r/GUI/3DScene.pm | 3 +++ lib/Slic3r/GUI/Plater/2DToolpaths.pm | 5 ++++- lib/Slic3r/GUI/Preferences.pm | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index b3c306850..c4fe92a04 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -67,6 +67,7 @@ our $Settings = { mode => 'simple', version_check => 1, autocenter => 1, + invert_zoom => 0, background_processing => 0, # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. # By default, Prusa has the controller hidden. @@ -124,6 +125,7 @@ sub OnInit { $last_version = $Settings->{_}{version}; $Settings->{_}{mode} ||= 'expert'; $Settings->{_}{autocenter} //= 1; + $Settings->{_}{invert_zoom} //= 0; $Settings->{_}{background_processing} //= 1; # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. $Settings->{_}{no_controller} //= 1; diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 2a37a9b75..56875acc9 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -127,6 +127,9 @@ sub new { # Calculate the zoom delta and apply it to the current zoom factor my $zoom = $e->GetWheelRotation() / $e->GetWheelDelta(); + if ($Slic3r::GUI::Settings->{_}{invert_zoom}) { + $zoom *= -1; + } $zoom = max(min($zoom, 4), -4); $zoom /= 10; $self->_zoom($self->_zoom / (1-$zoom)); diff --git a/lib/Slic3r/GUI/Plater/2DToolpaths.pm b/lib/Slic3r/GUI/Plater/2DToolpaths.pm index bc3d4e605..d39c53179 100644 --- a/lib/Slic3r/GUI/Plater/2DToolpaths.pm +++ b/lib/Slic3r/GUI/Plater/2DToolpaths.pm @@ -179,7 +179,10 @@ sub new { my $old_zoom = $self->_zoom; # Calculate the zoom delta and apply it to the current zoom factor - my $zoom = $e->GetWheelRotation() / $e->GetWheelDelta(); + my $zoom = -$e->GetWheelRotation() / $e->GetWheelDelta(); + if ($Slic3r::GUI::Settings->{_}{invert_zoom}) { + $zoom *= -1; + } $zoom = max(min($zoom, 4), -4); $zoom /= 10; $self->_zoom($self->_zoom / (1-$zoom)); diff --git a/lib/Slic3r/GUI/Preferences.pm b/lib/Slic3r/GUI/Preferences.pm index 431f642d6..91465fa64 100644 --- a/lib/Slic3r/GUI/Preferences.pm +++ b/lib/Slic3r/GUI/Preferences.pm @@ -52,6 +52,13 @@ sub new { tooltip => 'If this is enabled, Slic3r will auto-center objects around the print bed center.', default => $Slic3r::GUI::Settings->{_}{autocenter}, )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'invert_zoom', + type => 'bool', + label => 'Invert zoom in previews', + tooltip => 'If this is enabled, Slic3r will invert the direction of mouse-wheel zoom in preview panes.', + default => $Slic3r::GUI::Settings->{_}{invert_zoom}, + )); $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( opt_id => 'background_processing', type => 'bool', From 4e8f8f4b70f4a8426cc41e34e42da988056074dc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 11 Mar 2017 16:07:24 +0100 Subject: [PATCH 17/96] Try to fix OSX builds --- package/osx/make_dmg.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package/osx/make_dmg.sh b/package/osx/make_dmg.sh index c608040b6..dedd01f12 100755 --- a/package/osx/make_dmg.sh +++ b/package/osx/make_dmg.sh @@ -91,7 +91,9 @@ rm -rf $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidge echo "Relocating dylib paths..." for bundle in $(find $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/auto/Wx -name '*.bundle') $(find $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets -name '*.dylib' -type f); do chmod +w $bundle - find $SLIC3R_DIR/local-lib -name '*.dylib' -exec bash -c 'install_name_tool -change "{}" "@executable_path/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/$(basename {})" '$bundle \; + for dylib in $(otool -l $bundle | grep .dylib | grep local-lib | awk '{print $2}'); do + echo install_name_tool -change "$dylib" "@executable_path/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/$(basename $dylib)" $bundle + done done echo "Copying startup script..." From 6ed98e1c0235ebb8aa389bb574921de9ae69d549 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 11 Mar 2017 16:09:58 +0100 Subject: [PATCH 18/96] Typo --- package/osx/make_dmg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/osx/make_dmg.sh b/package/osx/make_dmg.sh index dedd01f12..d62fe991b 100755 --- a/package/osx/make_dmg.sh +++ b/package/osx/make_dmg.sh @@ -92,7 +92,7 @@ echo "Relocating dylib paths..." for bundle in $(find $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/auto/Wx -name '*.bundle') $(find $macosfolder/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets -name '*.dylib' -type f); do chmod +w $bundle for dylib in $(otool -l $bundle | grep .dylib | grep local-lib | awk '{print $2}'); do - echo install_name_tool -change "$dylib" "@executable_path/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/$(basename $dylib)" $bundle + install_name_tool -change "$dylib" "@executable_path/local-lib/lib/perl5/darwin-thread-multi-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/$(basename $dylib)" $bundle done done From 5d10d4c02b050cfbd73e67b47877f79655cc4464 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 11 Mar 2017 09:42:44 -0600 Subject: [PATCH 19/96] Added a timeout to the exception test to (hopefully) fail test on broken perl instead of waiting forever. --- xs/t/22_exception.t | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xs/t/22_exception.t b/xs/t/22_exception.t index ca2ffea89..b57255fa5 100644 --- a/xs/t/22_exception.t +++ b/xs/t/22_exception.t @@ -8,7 +8,10 @@ use Test::More tests => 1; { eval { + local $SIG{ALRM} = sub { die "Timed out waiting for exception\n" }; # NB: \n required + alarm 30; Slic3r::xspp_test_croak_hangs_on_strawberry(); + alarm 0; }; is $@, "xspp_test_croak_hangs_on_strawberry: exception catched\n", 'croak from inside a C++ exception delivered'; } From a2fb7313c64b71002d74dc172ce68446ec27c9e8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 11 Mar 2017 17:22:06 -0600 Subject: [PATCH 20/96] Configurable overhang threshold as function of perimeter width (#3752) * Fix automatic overhang threshold We should be supporting perimeters that are overhung further than half a perimeter out, rather than two times the perimeter width. Fixes: #2068 * Made the overhang detection configurable, up to 200 (the original value, which is still the default) * Set default to 60% as per https://github.com/alexrj/Slic3r/wiki/Support:-Requirements Removed some less useful enumerations (0-30%) * Folded in auto_threshold into support threshold as a % value --- lib/Slic3r/GUI/Tab.pm | 5 +++-- lib/Slic3r/Print/SupportMaterial.pm | 4 ++-- xs/src/libslic3r/PrintConfig.cpp | 15 +++++++++------ xs/src/libslic3r/PrintConfig.hpp | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index c515df76f..17e7e08ce 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -482,7 +482,7 @@ sub build { brim_connections_width brim_width support_material support_material_threshold support_material_enforce_layers raft_layers - support_material_pattern support_material_spacing support_material_angle + support_material_pattern support_material_spacing support_material_angle support_material_interface_layers support_material_interface_spacing support_material_contact_distance dont_support_bridges notes @@ -864,10 +864,11 @@ sub _update { my $have_support_material = $config->support_material || $config->raft_layers > 0; my $have_support_interface = $config->support_material_interface_layers > 0; $self->get_field($_)->toggle($have_support_material) - for qw(support_material_threshold support_material_pattern + for qw(support_material_threshold support_material_pattern support_material_spacing support_material_angle support_material_interface_layers dont_support_bridges support_material_extrusion_width support_material_contact_distance); + $self->get_field($_)->toggle($have_support_material && $have_support_interface) for qw(support_material_interface_spacing support_material_interface_extruder support_material_interface_speed); diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index 34829a2a2..02b2e5375 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -92,7 +92,7 @@ sub contact_area { # if user specified a custom angle threshold, convert it to radians my $threshold_rad; - if ($self->object_config->support_material_threshold) { + if (!$self->object_config->support_material_threshold =~ /%$/) { $threshold_rad = deg2rad($self->object_config->support_material_threshold + 1); # +1 makes the threshold inclusive Slic3r::debugf "Threshold angle = %d°\n", rad2deg($threshold_rad); } @@ -152,7 +152,7 @@ sub contact_area { } else { $diff = diff( [ map $_->p, @{$layerm->slices} ], - offset([ map @$_, @{$lower_layer->slices} ], +$fw*2), + offset([ map @$_, @{$lower_layer->slices} ], +$self->object_config->get_abs_value_over('support_material_threshold', $fw)), ); # collapse very tiny spots diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index aca51e334..e024393ba 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1291,6 +1291,9 @@ PrintConfigDef::PrintConfigDef() def->min = 0; def->default_value = new ConfigOptionFloat(2.5); + + + def = this->add("support_material_speed", coFloat); def->label = "Support material"; def->gui_type = "f_enum_open"; @@ -1303,15 +1306,15 @@ PrintConfigDef::PrintConfigDef() def->enum_labels.push_back("auto"); def->default_value = new ConfigOptionFloat(60); - def = this->add("support_material_threshold", coInt); + def = this->add("support_material_threshold", coFloatOrPercent); def->label = "Overhang threshold"; def->category = "Support material"; - def->tooltip = "Support material will not be generated for overhangs whose slope angle (90° = vertical) is above the given threshold. In other words, this value represent the most horizontal slope (measured from the horizontal plane) that you can print without support material. Set to zero for automatic detection (recommended)."; - def->sidetext = "°"; - def->cli = "support-material-threshold=i"; + def->tooltip = "Support material will not be generated for overhangs whose slope angle (90° = vertical) is above the given threshold. In other words, this value represent the most horizontal slope (measured from the horizontal plane) that you can print without support material. Set to a percentage to automatically detect based on some % of overhanging perimeter width instead (recommended)."; + def->sidetext = "° (or %)"; + def->cli = "support-material-threshold=s"; def->min = 0; - def->max = 90; - def->default_value = new ConfigOptionInt(0); + def->max = 300; + def->default_value = new ConfigOptionFloatOrPercent(60, true); def = this->add("temperature", coInts); def->label = "Other layers"; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 27c5d4e75..3694819c6 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -161,7 +161,7 @@ class PrintObjectConfig : public virtual StaticPrintConfig ConfigOptionEnum support_material_pattern; ConfigOptionFloat support_material_spacing; ConfigOptionFloat support_material_speed; - ConfigOptionInt support_material_threshold; + ConfigOptionFloatOrPercent support_material_threshold; ConfigOptionFloat xy_size_compensation; PrintObjectConfig(bool initialize = true) : StaticPrintConfig() { From f670ad68212fb0df92e2614f3fbc4b41dbef4f37 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 11 Mar 2017 23:35:22 +0100 Subject: [PATCH 21/96] New Interior Brim option. #2026 --- lib/Slic3r/GUI/3DScene.pm | 3 +- lib/Slic3r/GUI/Tab.pm | 6 ++- lib/Slic3r/Print/GCode.pm | 3 +- slic3r.pl | 2 + xs/src/libslic3r/ExPolygonCollection.cpp | 14 +++-- xs/src/libslic3r/ExPolygonCollection.hpp | 1 + xs/src/libslic3r/Print.cpp | 65 +++++++++++++++++++----- xs/src/libslic3r/PrintConfig.cpp | 10 +++- xs/src/libslic3r/PrintConfig.hpp | 2 + 9 files changed, 85 insertions(+), 21 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 56875acc9..0e6ba3c8f 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -1296,6 +1296,7 @@ sub load_print_toolpaths { return if !$print->step_done(STEP_BRIM); return if !$print->has_skirt && $print->config->brim_width == 0 + && $print->config->interior_brim_width == 0 && $print->config->brim_connections_width == 0; my $qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; @@ -1308,7 +1309,7 @@ sub load_print_toolpaths { } else { $skirt_height = min($print->config->skirt_height, $print->total_layer_count); } - $skirt_height ||= 1 if $print->config->brim_width > 0; + $skirt_height ||= 1 if $print->config->brim_width > 0 || $print->config->interior_brim_width; # get first $skirt_height layers (maybe this should be moved to a PrintObject method?) my $object0 = $print->get_object(0); diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 17e7e08ce..e6a5c0f8a 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -479,7 +479,7 @@ sub build { perimeter_acceleration infill_acceleration bridge_acceleration first_layer_acceleration default_acceleration skirts skirt_distance skirt_height min_skirt_length - brim_connections_width brim_width + brim_connections_width brim_width interior_brim_width support_material support_material_threshold support_material_enforce_layers raft_layers support_material_pattern support_material_spacing support_material_angle @@ -572,6 +572,7 @@ sub build { { my $optgroup = $page->new_optgroup('Brim'); $optgroup->append_single_option_line('brim_width'); + $optgroup->append_single_option_line('interior_brim_width'); $optgroup->append_single_option_line('brim_connections_width'); } } @@ -857,7 +858,8 @@ sub _update { $self->get_field($_)->toggle($have_skirt) for qw(skirt_distance skirt_height); - my $have_brim = $config->brim_width > 0 || $config->brim_connections_width; + my $have_brim = $config->brim_width > 0 || $config->interior_brim_width + || $config->brim_connections_width; # perimeter_extruder uses the same logic as in Print::extruders() $self->get_field('perimeter_extruder')->toggle($have_perimeters || $have_brim); diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 086f7e33f..d6bd99ac0 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -318,7 +318,8 @@ sub process_layer { # check whether we're going to apply spiralvase logic if (defined $self->_spiral_vase) { $self->_spiral_vase->enable( - ($layer->id > 0 || $self->print->config->brim_width == 0 || $self->print->config->brim_connections_width == 0) + ($layer->id > 0 || $self->print->config->brim_width == 0 + || $self->print->config->interior_brim_width == 0 || $self->print->config->brim_connections_width == 0) && ($layer->id >= $self->print->config->skirt_height && !$self->print->has_infinite_skirt) && !defined(first { $_->region->config->bottom_solid_layers > $layer->id } @{$layer->regions}) && !defined(first { $_->perimeters->items_count > 1 } @{$layer->regions}) diff --git a/slic3r.pl b/slic3r.pl index 0f9c8e57f..c9c282e8f 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -530,6 +530,8 @@ $j of filament on the first layer, for each extruder (mm, 0+, default: $config->{min_skirt_length}) --brim-width Width of the brim that will get added to each object to help adhesion (mm, default: $config->{brim_width}) + --interior-brim-width Width of the brim that will get printed inside object holes to help adhesion + (mm, default: $config->{interior_brim_width}) Transform options: --scale Factor for scaling input object (default: 1) diff --git a/xs/src/libslic3r/ExPolygonCollection.cpp b/xs/src/libslic3r/ExPolygonCollection.cpp index 10e036210..90498a42d 100644 --- a/xs/src/libslic3r/ExPolygonCollection.cpp +++ b/xs/src/libslic3r/ExPolygonCollection.cpp @@ -116,12 +116,20 @@ Polygons ExPolygonCollection::contours() const { Polygons contours; - for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) { - contours.push_back(it->contour); - } + for (const ExPolygon &ex : this->expolygons) + contours.push_back(ex.contour); return contours; } +Polygons +ExPolygonCollection::holes() const +{ + Polygons holes; + for (const ExPolygon &ex : this->expolygons) + append_to(holes, ex.holes); + return holes; +} + void ExPolygonCollection::append(const ExPolygons &expp) { diff --git a/xs/src/libslic3r/ExPolygonCollection.hpp b/xs/src/libslic3r/ExPolygonCollection.hpp index e63dd9142..89728c822 100644 --- a/xs/src/libslic3r/ExPolygonCollection.hpp +++ b/xs/src/libslic3r/ExPolygonCollection.hpp @@ -31,6 +31,7 @@ class ExPolygonCollection Polygon convex_hull() const; Lines lines() const; Polygons contours() const; + Polygons holes() const; void append(const ExPolygons &expolygons); }; diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 9dec28e9f..f1bc284d9 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -167,6 +167,7 @@ Print::invalidate_state_by_config_options(const std::vector || *opt_key == "ooze_prevention") { steps.insert(psSkirt); } else if (*opt_key == "brim_width" + || *opt_key == "interior_brim_width" || *opt_key == "brim_connections_width") { steps.insert(psBrim); steps.insert(psSkirt); @@ -308,7 +309,10 @@ Print::object_extruders() const FOREACH_REGION(this, region) { // these checks reflect the same logic used in the GUI for enabling/disabling // extruder selection fields - if ((*region)->config.perimeters.value > 0 || this->config.brim_width.value > 0 || this->config.brim_connections_width.value > 0) + if ((*region)->config.perimeters.value > 0 + || this->config.brim_width.value > 0 + || this->config.interior_brim_width.value > 0 + || this->config.brim_connections_width.value > 0) extruders.insert((*region)->config.perimeter_extruder - 1); if ((*region)->config.fill_density.value > 0) @@ -790,7 +794,9 @@ Print::_make_brim() // checking whether we need to generate them this->brim.clear(); - if (this->config.brim_width == 0 && this->config.brim_connections_width == 0) { + if (this->config.brim_width == 0 + && this->config.interior_brim_width == 0 + && this->config.brim_connections_width == 0) { this->state.set_done(psBrim); return; } @@ -819,12 +825,10 @@ Print::_make_brim() it != support_layer0.support_interface_fills.entities.end(); ++it) append_to(object_islands, offset((*it)->as_polyline(), grow_distance)); } - for (Points::const_iterator copy = (*object)->_shifted_copies.begin(); copy != (*object)->_shifted_copies.end(); - ++copy) { - for (Polygons::const_iterator p = object_islands.begin(); p != object_islands.end(); ++p) { - Polygon p2 = *p; - p2.translate(*copy); - islands.push_back(p2); + for (const Point © : (*object)->_shifted_copies) { + for (Polygon p : object_islands) { + p.translate(copy); + islands.push_back(p); } } } @@ -855,17 +859,17 @@ Print::_make_brim() } if (this->config.brim_connections_width > 0) { - // get islands to connects - for (Polygons::iterator p = islands.begin(); p != islands.end(); ++p) - *p = Geometry::convex_hull(p->points); + // get islands to connect + for (Polygon &p : islands) + p = Geometry::convex_hull(p.points); islands = offset(islands, flow.scaled_spacing() * (num_loops-0.2), 10000, jtSquare); // compute centroid for each island Points centroids; centroids.reserve(islands.size()); - for (Polygons::const_iterator p = islands.begin(); p != islands.end(); ++p) - centroids.push_back(p->centroid()); + for (const Polygon &p : islands) + centroids.push_back(p.centroid()); // in order to check visibility we need to account for the connections width, // so let's use grown islands @@ -912,6 +916,41 @@ Print::_make_brim() } } + if (this->config.interior_brim_width > 0) { + // collect all island holes to fill + Polygons holes; + for (PrintObject* object : this->objects) { + const Layer &layer0 = *object->get_layer(0); + + const Polygons o_holes = layer0.slices.holes(); + for (const Point © : object->_shifted_copies) { + for (Polygon p : o_holes) { + p.translate(copy); + holes.push_back(p); + } + } + } + + Polygons loops; + const int num_loops = floor(this->config.interior_brim_width / flow.width + 0.5); + for (int i = 1; i <= num_loops; ++i) { + append_to(loops, offset2( + holes, + -flow.scaled_spacing() * (i + 0.5), + flow.scaled_spacing(), + 100000, + ClipperLib::jtSquare + )); + } + + loops = union_pt_chained(loops); + for (const Polygon &p : loops) { + ExtrusionPath path(erSkirt, mm3_per_mm, flow.width, first_layer_height); + path.polyline = p.split_at_first_point(); + this->brim.append(ExtrusionLoop(path)); + } + } + this->state.set_done(psBrim); } diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index e024393ba..9cee1a147 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -103,7 +103,7 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionFloat(0); def = this->add("brim_width", coFloat); - def->label = "Brim width"; + def->label = "Exterior brim width"; def->tooltip = "Horizontal width of the brim that will be printed around each object on the first layer."; def->sidetext = "mm"; def->cli = "brim-width=f"; @@ -653,6 +653,14 @@ PrintConfigDef::PrintConfigDef() def->enum_labels.push_back("auto"); def->default_value = new ConfigOptionFloat(80); + def = this->add("interior_brim_width", coFloat); + def->label = "Interior brim width"; + def->tooltip = "Horizontal width of the brim that will be printed inside object holes on the first layer."; + def->sidetext = "mm"; + def->cli = "interior-brim-width=f"; + def->min = 0; + def->default_value = new ConfigOptionFloat(0); + def = this->add("interface_shells", coBool); def->label = "Interface shells"; def->tooltip = "Force the generation of solid shells between adjacent materials/volumes. Useful for multi-extruder prints with translucent materials or manual soluble support material."; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 3694819c6..715d84296 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -395,6 +395,7 @@ class PrintConfig : public GCodeConfig ConfigOptionBool gcode_arcs; ConfigOptionFloat infill_acceleration; ConfigOptionBool infill_first; + ConfigOptionFloat interior_brim_width; ConfigOptionInt max_fan_speed; ConfigOptionInt min_fan_speed; ConfigOptionFloat min_print_speed; @@ -455,6 +456,7 @@ class PrintConfig : public GCodeConfig OPT_PTR(gcode_arcs); OPT_PTR(infill_acceleration); OPT_PTR(infill_first); + OPT_PTR(interior_brim_width); OPT_PTR(max_fan_speed); OPT_PTR(min_fan_speed); OPT_PTR(min_print_speed); From cf0021c101e028c2eef3885c55724a1c0ef0cae0 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 12 Mar 2017 00:29:49 +0100 Subject: [PATCH 22/96] Put internal brim also inside objects when they have no infill. #2026 --- xs/src/libslic3r/Print.cpp | 22 +++++++++++----------- xs/src/libslic3r/Print.hpp | 9 ++++++--- xs/src/libslic3r/PrintObject.cpp | 12 ------------ 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index f1bc284d9..4ad4e4136 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -73,12 +73,6 @@ Print::clear_objects() this->clear_regions(); } -PrintObject* -Print::get_object(size_t idx) -{ - return objects.at(idx); -} - void Print::delete_object(size_t idx) { @@ -919,10 +913,18 @@ Print::_make_brim() if (this->config.interior_brim_width > 0) { // collect all island holes to fill Polygons holes; - for (PrintObject* object : this->objects) { + for (const PrintObject* object : this->objects) { const Layer &layer0 = *object->get_layer(0); - const Polygons o_holes = layer0.slices.holes(); + Polygons o_holes = layer0.slices.holes(); + + // When we have no infill on this layer, consider the internal part + // of the model as a hole. + for (const LayerRegion* layerm : layer0.regions) { + if (layerm->fills.empty()) + append_to(o_holes, (Polygons)layerm->fill_surfaces); + } + for (const Point © : object->_shifted_copies) { for (Polygon p : o_holes) { p.translate(copy); @@ -937,9 +939,7 @@ Print::_make_brim() append_to(loops, offset2( holes, -flow.scaled_spacing() * (i + 0.5), - flow.scaled_spacing(), - 100000, - ClipperLib::jtSquare + flow.scaled_spacing() )); } diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 092fc84c3..a5bc63def 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -118,14 +118,16 @@ class PrintObject size_t total_layer_count() const; size_t layer_count() const; void clear_layers(); - Layer* get_layer(int idx); + Layer* get_layer(int idx) { return this->layers.at(idx); }; + const Layer* get_layer(int idx) const { return this->layers.at(idx); }; // print_z: top of the layer; slice_z: center of the layer. Layer* add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z); void delete_layer(int idx); size_t support_layer_count() const; void clear_support_layers(); - SupportLayer* get_support_layer(int idx); + SupportLayer* get_support_layer(int idx) { return this->support_layers.at(idx); }; + const SupportLayer* get_support_layer(int idx) const { return this->support_layers.at(idx); }; SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z); void delete_support_layer(int idx); @@ -179,7 +181,8 @@ class Print // methods for handling objects void clear_objects(); - PrintObject* get_object(size_t idx); + PrintObject* get_object(size_t idx) { return this->objects.at(idx); }; + const PrintObject* get_object(size_t idx) const { return this->objects.at(idx); }; void delete_object(size_t idx); void reload_object(size_t idx); bool reload_model_instances(); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index b8ab9cdbf..cfa0ef3c7 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -166,12 +166,6 @@ PrintObject::clear_layers() this->delete_layer(i); } -Layer* -PrintObject::get_layer(int idx) -{ - return this->layers.at(idx); -} - Layer* PrintObject::add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z) { @@ -201,12 +195,6 @@ PrintObject::clear_support_layers() this->delete_support_layer(i); } -SupportLayer* -PrintObject::get_support_layer(int idx) -{ - return this->support_layers.at(idx); -} - SupportLayer* PrintObject::add_support_layer(int id, coordf_t height, coordf_t print_z) { From a193297b20ca559200b3cea37c4960479d0c6f6b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 12 Mar 2017 00:50:36 +0100 Subject: [PATCH 23/96] Align speed and extrusion width fields --- lib/Slic3r/GUI/OptionsGroup.pm | 11 ++++++----- lib/Slic3r/GUI/Tab.pm | 29 +++++++++++------------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index fac5394f8..2a00b1a0c 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -361,7 +361,7 @@ has 'full_labels' => (is => 'ro', default => sub { 0 }); has '_opt_map' => (is => 'ro', default => sub { {} }); sub get_option { - my ($self, $opt_key, $opt_index) = @_; + my ($self, $opt_key, $opt_index, %params) = @_; $opt_index //= -1; @@ -392,24 +392,25 @@ sub get_option { labels => $optdef->{labels}, values => $optdef->{values}, readonly => $optdef->{readonly}, + %params, ); } sub create_single_option_line { - my ($self, $opt_key, $opt_index) = @_; + my ($self, $opt_key, $opt_index, %params) = @_; my $option; if (ref($opt_key)) { $option = $opt_key; } else { - $option = $self->get_option($opt_key, $opt_index); + $option = $self->get_option($opt_key, $opt_index, %params); } return $self->SUPER::create_single_option_line($option); } sub append_single_option_line { - my ($self, $option, $opt_index) = @_; - return $self->append_line($self->create_single_option_line($option, $opt_index)); + my ($self, $option, $opt_index, %params) = @_; + return $self->append_line($self->create_single_option_line($option, $opt_index, %params)); } sub reload_config { diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 97c27b684..e24b7429e 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -605,16 +605,12 @@ sub build { my $page = $self->add_options_page('Speed', 'time.png'); { my $optgroup = $page->new_optgroup('Speed for print moves'); - $optgroup->append_single_option_line('perimeter_speed'); - $optgroup->append_single_option_line('small_perimeter_speed'); - $optgroup->append_single_option_line('external_perimeter_speed'); - $optgroup->append_single_option_line('infill_speed'); - $optgroup->append_single_option_line('solid_infill_speed'); - $optgroup->append_single_option_line('top_solid_infill_speed'); - $optgroup->append_single_option_line('gap_fill_speed'); - $optgroup->append_single_option_line('support_material_speed'); - $optgroup->append_single_option_line('support_material_interface_speed'); - $optgroup->append_single_option_line('bridge_speed'); + $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 + support_material_speed support_material_interface_speed + ); } { my $optgroup = $page->new_optgroup('Speed for non-print moves'); @@ -666,14 +662,11 @@ sub build { my $optgroup = $page->new_optgroup('Extrusion width', label_width => 180, ); - $optgroup->append_single_option_line('extrusion_width'); - $optgroup->append_single_option_line('first_layer_extrusion_width'); - $optgroup->append_single_option_line('perimeter_extrusion_width'); - $optgroup->append_single_option_line('external_perimeter_extrusion_width'); - $optgroup->append_single_option_line('infill_extrusion_width'); - $optgroup->append_single_option_line('solid_infill_extrusion_width'); - $optgroup->append_single_option_line('top_infill_extrusion_width'); - $optgroup->append_single_option_line('support_material_extrusion_width'); + $optgroup->append_single_option_line($_, undef, width => 100) + for qw(extrusion_width first_layer_extrusion_width + perimeter_extrusion_width external_perimeter_extrusion_width + infill_extrusion_width solid_infill_extrusion_width + top_infill_extrusion_width support_material_extrusion_width); } { my $optgroup = $page->new_optgroup('Overlap'); From 795a3d06fa48369631649780dbb7b18aac74dec3 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 12 Mar 2017 11:02:34 +0100 Subject: [PATCH 24/96] Only enable ooze_prevention when print uses more than one extruder. #3334 --- lib/Slic3r/Print/GCode.pm | 4 ++-- xs/src/libslic3r/PrintConfig.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index cf780e54b..b851f5242 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -144,12 +144,12 @@ sub export { } # calculate wiping points if needed - if ($self->config->ooze_prevention) { + if ($self->config->ooze_prevention && (my @extruders = @{$self->print->extruders}) > 1) { my @skirt_points = map @$_, map @$_, @{$self->print->skirt}; if (@skirt_points) { my $outer_skirt = convex_hull(\@skirt_points); my @skirts = (); - foreach my $extruder_id (@{$self->print->extruders}) { + foreach my $extruder_id (@extruders) { my $extruder_offset = $self->config->get_at('extruder_offset', $extruder_id); push @skirts, my $s = $outer_skirt->clone; $s->translate(-scale($extruder_offset->x), -scale($extruder_offset->y)); #) diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index eb51b6637..a91816d5f 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -789,7 +789,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("ooze_prevention", coBool); def->label = "Enable"; - def->tooltip = "This option will drop the temperature of the inactive extruders to prevent oozing. It will enable a tall skirt automatically and move extruders outside such skirt when changing temperatures."; + def->tooltip = "During multi-extruder prints, this option will drop the temperature of the inactive extruders to prevent oozing. It will enable a tall skirt automatically and move extruders outside such skirt when changing temperatures."; def->cli = "ooze-prevention!"; def->default_value = new ConfigOptionBool(false); From e6553599b6b7a17024cc654f95442cef6631300c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 12 Mar 2017 11:37:37 +0100 Subject: [PATCH 25/96] Add regression test for gaps between top solid infill and perimeters when top solid infill extrusion width is very narrow. #2697 --- t/fill.t | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/t/fill.t b/t/fill.t index a9e505c16..c9cb21391 100644 --- a/t/fill.t +++ b/t/fill.t @@ -2,7 +2,7 @@ use Test::More; use strict; use warnings; -plan tests => 92; +plan tests => 93; BEGIN { use FindBin; @@ -10,10 +10,10 @@ BEGIN { use local::lib "$FindBin::Bin/../local-lib"; } -use List::Util qw(first sum); +use List::Util qw(first sum max); use Slic3r; use Slic3r::Geometry qw(PI X Y scaled_epsilon scale unscale convex_hull); -use Slic3r::Geometry::Clipper qw(union diff diff_ex offset offset2_ex diff_pl); +use Slic3r::Geometry::Clipper qw(union diff diff_ex offset offset2_ex diff_pl union_ex); use Slic3r::Surface qw(:types); use Slic3r::Test; @@ -373,4 +373,46 @@ for my $pattern (qw(rectilinear honeycomb hilbertcurve concentric)) { is scalar(@$diff), 0, 'no missing parts in solid shell when fill_density is 0'; } +{ + # GH: #2697 + my $config = Slic3r::Config->new_from_defaults; + $config->set('perimeter_extrusion_width', 0.72); + $config->set('top_infill_extrusion_width', 0.1); + $config->set('infill_extruder', 2); # in order to distinguish infill + $config->set('solid_infill_extruder', 2); # in order to distinguish infill + + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + my %infill = (); # Z => [ Line, Line ... ] + my %other = (); # Z => [ Line, Line ... ] + my $tool = undef; + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if ($cmd =~ /^T(\d+)/) { + $tool = $1; + } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) { + my $z = 1 * $self->Z; + my $line = Slic3r::Line->new_scale( + [ $self->X, $self->Y ], + [ $info->{new_X}, $info->{new_Y} ], + ); + if ($tool == $config->infill_extruder-1) { + $infill{$z} //= []; + push @{$infill{$z}}, $line; + } else { + $other{$z} //= []; + push @{$other{$z}}, $line; + } + } + }); + my $top_z = max(keys %infill); + my $top_infill_grow_d = scale($config->top_infill_extrusion_width)/2; + my $top_infill = union([ map @{$_->grow($top_infill_grow_d)}, @{ $infill{$top_z} } ]); + my $perimeters_grow_d = scale($config->perimeter_extrusion_width)/2; + my $perimeters = union([ map @{$_->grow($perimeters_grow_d)}, @{ $other{$top_z} } ]); + my $covered = union_ex([ @$top_infill, @$perimeters ]); + my @holes = map @{$_->holes}, @$covered; + ok sum(map unscale unscale $_->area*-1, @holes) < 1, 'no gaps between top solid infill and perimeters'; +} + __END__ From 4b4a0c8a5cc7c607fee7680e7c5819d9a697c317 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 12 Mar 2017 13:01:14 +0100 Subject: [PATCH 26/96] Split external_fill_pattern into top_infill_pattern and bottom_infill_pattern. Retrocompatibile change. #945 --- lib/Slic3r/Config.pm | 6 ++- lib/Slic3r/GUI/Tab.pm | 17 +++++-- slic3r.pl | 5 +- xs/src/libslic3r/Config.cpp | 11 ++++- xs/src/libslic3r/Config.hpp | 1 + xs/src/libslic3r/Fill/FillPlanePath.hpp | 3 ++ xs/src/libslic3r/LayerRegionFill.cpp | 8 ++-- xs/src/libslic3r/PrintConfig.cpp | 63 ++++++++++++++++++------- xs/src/libslic3r/PrintConfig.hpp | 6 ++- xs/src/libslic3r/PrintObject.cpp | 3 +- 10 files changed, 91 insertions(+), 32 deletions(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index a399a8333..5168ddf94 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -265,8 +265,10 @@ sub validate { if !first { $_ eq $self->fill_pattern } @{$Options->{fill_pattern}{values}}; # --external-fill-pattern - die "Invalid value for --external-fill-pattern\n" - if !first { $_ eq $self->external_fill_pattern } @{$Options->{external_fill_pattern}{values}}; + die "Invalid value for --top-infill-pattern\n" + if !first { $_ eq $self->top_infill_pattern } @{$Options->{top_infill_pattern}{values}}; + die "Invalid value for --bottom-infill-pattern\n" + if !first { $_ eq $self->bottom_infill_pattern } @{$Options->{bottom_infill_pattern}{values}}; # --fill-density die "The selected fill pattern is not supposed to work at 100% density\n" diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index e24b7429e..c6190ea4d 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -466,7 +466,7 @@ sub build { top_solid_layers bottom_solid_layers extra_perimeters avoid_crossing_perimeters thin_walls overhangs seam_position external_perimeters_first - fill_density fill_pattern external_fill_pattern fill_gaps + fill_density fill_pattern top_infill_pattern bottom_infill_pattern fill_gaps infill_every_layers infill_only_where_needed solid_infill_every_layers fill_angle solid_infill_below_area only_retract_when_crossing_perimeters infill_first @@ -542,7 +542,14 @@ sub build { my $optgroup = $page->new_optgroup('Infill'); $optgroup->append_single_option_line('fill_density'); $optgroup->append_single_option_line('fill_pattern'); - $optgroup->append_single_option_line('external_fill_pattern'); + { + my $line = Slic3r::GUI::OptionsGroup::Line->new( + label => 'External infill pattern', + ); + $line->append_option($optgroup->get_option('top_infill_pattern')); + $line->append_option($optgroup->get_option('bottom_infill_pattern')); + $optgroup->append_line($line); + } } { my $optgroup = $page->new_optgroup('Reducing printing time'); @@ -794,7 +801,7 @@ sub _update { } if ($config->fill_density == 100 - && !first { $_ eq $config->fill_pattern } @{$Slic3r::Config::Options->{external_fill_pattern}{values}}) { + && !first { $_ eq $config->fill_pattern } @{$Slic3r::Config::Options->{top_infill_pattern}{values}}) { my $dialog = Wx::MessageDialog->new($self, "The " . $config->fill_pattern . " infill pattern is not supposed to work at 100% density.\n" . "\nShall I switch to rectilinear fill pattern?", @@ -824,8 +831,8 @@ sub _update { my $have_solid_infill = ($config->top_solid_layers > 0) || ($config->bottom_solid_layers > 0); # solid_infill_extruder uses the same logic as in Print::extruders() $self->get_field($_)->toggle($have_solid_infill) - for qw(external_fill_pattern infill_first solid_infill_extruder solid_infill_extrusion_width - solid_infill_speed); + for qw(top_infill_pattern bottom_infill_pattern infill_first solid_infill_extruder + solid_infill_extrusion_width solid_infill_speed); $self->get_field($_)->toggle($have_infill || $have_solid_infill) for qw(fill_angle infill_extrusion_width infill_speed bridge_speed); diff --git a/slic3r.pl b/slic3r.pl index c9c282e8f..ee9e45214 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -431,7 +431,10 @@ $j --fill-angle Infill angle in degrees (range: 0-90, default: $config->{fill_angle}) --fill-pattern Pattern to use to fill non-solid layers (default: $config->{fill_pattern}) --fill-gaps Fill gaps with single passes (default: yes) - --external-fill-pattern Pattern to use to fill solid layers (default: $config->{external_fill_pattern}) + --external-infill-pattern Pattern to use to fill solid layers. + (Shortcut for --top-infill-pattern and --bottom-infill-pattern) + --top-infill-pattern Pattern to use to fill top solid layers (default: $config->{top_infill_pattern}) + --bottom-infill-pattern Pattern to use to fill bottom solid layers (default: $config->{bottom_infill_pattern}) --start-gcode Load initial G-code from the supplied file. This will overwrite the default command (home all axes [G28]). --end-gcode Load final G-code from the supplied file. This will overwrite diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index ed8ffc468..1f366f3cb 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -192,7 +192,9 @@ ConfigOptionDef::ConfigOptionDef(const ConfigOptionDef &other) full_label(other.full_label), category(other.category), tooltip(other.tooltip), sidetext(other.sidetext), cli(other.cli), ratio_over(other.ratio_over), multiline(other.multiline), full_width(other.full_width), readonly(other.readonly), - height(other.height), width(other.width), min(other.min), max(other.max) + height(other.height), width(other.width), min(other.min), max(other.max), + aliases(other.aliases), shortcut(other.shortcut), enum_values(other.enum_values), + enum_labels(other.enum_labels), enum_keys_map(other.enum_keys_map) { if (other.default_value != NULL) this->default_value = other.default_value->clone(); @@ -212,6 +214,13 @@ ConfigDef::add(const t_config_option_key &opt_key, ConfigOptionType type) return opt; } +ConfigOptionDef* +ConfigDef::add(const t_config_option_key &opt_key, const ConfigOptionDef &def) +{ + this->options.emplace(opt_key, def); + return &this->options[opt_key]; +} + const ConfigOptionDef* ConfigDef::get(const t_config_option_key &opt_key) const { diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 128ef04bc..8e375701e 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -641,6 +641,7 @@ class ConfigDef public: t_optiondef_map options; ConfigOptionDef* add(const t_config_option_key &opt_key, ConfigOptionType type); + ConfigOptionDef* add(const t_config_option_key &opt_key, const ConfigOptionDef &def); const ConfigOptionDef* get(const t_config_option_key &opt_key) const; void merge(const ConfigDef &other); }; diff --git a/xs/src/libslic3r/Fill/FillPlanePath.hpp b/xs/src/libslic3r/Fill/FillPlanePath.hpp index 7e308aac5..0956db4e1 100644 --- a/xs/src/libslic3r/Fill/FillPlanePath.hpp +++ b/xs/src/libslic3r/Fill/FillPlanePath.hpp @@ -35,6 +35,7 @@ class FillArchimedeanChords : public FillPlanePath public: virtual Fill* clone() const { return new FillArchimedeanChords(*this); }; virtual ~FillArchimedeanChords() {} + virtual bool can_solid() const { return true; }; protected: virtual bool _centered() const { return true; } @@ -46,6 +47,7 @@ class FillHilbertCurve : public FillPlanePath public: virtual Fill* clone() const { return new FillHilbertCurve(*this); }; virtual ~FillHilbertCurve() {} + virtual bool can_solid() const { return true; }; protected: virtual bool _centered() const { return false; } @@ -57,6 +59,7 @@ class FillOctagramSpiral : public FillPlanePath public: virtual Fill* clone() const { return new FillOctagramSpiral(*this); }; virtual ~FillOctagramSpiral() {} + virtual bool can_solid() const { return true; }; protected: virtual bool _centered() const { return true; } diff --git a/xs/src/libslic3r/LayerRegionFill.cpp b/xs/src/libslic3r/LayerRegionFill.cpp index 0b4276439..954f1d135 100644 --- a/xs/src/libslic3r/LayerRegionFill.cpp +++ b/xs/src/libslic3r/LayerRegionFill.cpp @@ -67,7 +67,9 @@ LayerRegion::make_fill() group_attrib[i].is_solid = true; group_attrib[i].fw = (surface.surface_type == stTop) ? top_solid_infill_flow.width : solid_infill_flow.width; - group_attrib[i].pattern = surface.is_external() ? this->region()->config.external_fill_pattern.value : ipRectilinear; + group_attrib[i].pattern = surface.surface_type == stTop ? this->region()->config.top_infill_pattern.value + : surface.is_bottom() ? this->region()->config.bottom_infill_pattern.value + : ipRectilinear; } // Loop through solid groups, find compatible groups and append them to this one. for (size_t i = 0; i < groups.size(); ++i) { @@ -171,8 +173,8 @@ LayerRegion::make_fill() if (surface.is_solid()) { density = 100.; - fill_pattern = (surface.is_external() && !is_bridge) - ? this->region()->config.external_fill_pattern.value + fill_pattern = (surface.surface_type == stTop) ? this->region()->config.top_infill_pattern.value + : (surface.is_bottom() && !is_bridge) ? this->region()->config.bottom_infill_pattern.value : ipRectilinear; } else if (density <= 0) continue; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index a91816d5f..99713270c 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -5,6 +5,20 @@ namespace Slic3r { PrintConfigDef::PrintConfigDef() { + ConfigOptionDef external_fill_pattern; + external_fill_pattern.type = coEnum; + external_fill_pattern.enum_keys_map = ConfigOptionEnum::get_enum_values(); + external_fill_pattern.enum_values.push_back("rectilinear"); + external_fill_pattern.enum_values.push_back("concentric"); + external_fill_pattern.enum_values.push_back("hilbertcurve"); + external_fill_pattern.enum_values.push_back("archimedeanchords"); + external_fill_pattern.enum_values.push_back("octagramspiral"); + external_fill_pattern.enum_labels.push_back("Rectilinear"); + external_fill_pattern.enum_labels.push_back("Concentric"); + external_fill_pattern.enum_labels.push_back("Hilbert Curve"); + external_fill_pattern.enum_labels.push_back("Archimedean Chords"); + external_fill_pattern.enum_labels.push_back("Octagram Spiral"); + ConfigOptionDef* def; def = this->add("avoid_crossing_perimeters", coBool); @@ -47,6 +61,14 @@ PrintConfigDef::PrintConfigDef() def->height = 50; def->default_value = new ConfigOptionString(""); + def = this->add("bottom_infill_pattern", external_fill_pattern); + def->label = "Bottom"; + def->full_label = "Bottom infill pattern"; + def->category = "Infill"; + def->tooltip = "Infill pattern for bottom layers. This only affects the external visible layer, and not its adjacent solid shells."; + def->cli = "bottom-infill-pattern=s"; + def->default_value = new ConfigOptionEnum(ipRectilinear); + def = this->add("bottom_solid_layers", coInt); def->label = "Bottom"; def->category = "Layers and Perimeters"; @@ -177,27 +199,15 @@ PrintConfigDef::PrintConfigDef() def->default_value = opt; } - def = this->add("external_fill_pattern", coEnum); + def = this->add("external_fill_pattern", external_fill_pattern); def->label = "Top/bottom fill pattern"; def->category = "Infill"; def->tooltip = "Fill pattern for top/bottom infill. This only affects the external visible layer, and not its adjacent solid shells."; - def->cli = "external-fill-pattern|solid-fill-pattern=s"; - def->enum_keys_map = ConfigOptionEnum::get_enum_values(); - def->enum_values.push_back("rectilinear"); - def->enum_values.push_back("alignedrectilinear"); - def->enum_values.push_back("concentric"); - def->enum_values.push_back("hilbertcurve"); - def->enum_values.push_back("archimedeanchords"); - def->enum_values.push_back("octagramspiral"); - def->enum_labels.push_back("Rectilinear"); - def->enum_labels.push_back("Aligned Rectilinear"); - def->enum_labels.push_back("Concentric"); - def->enum_labels.push_back("Hilbert Curve"); - def->enum_labels.push_back("Archimedean Chords"); - def->enum_labels.push_back("Octagram Spiral"); + def->cli = "external-fill-pattern|external-infill-pattern|solid-fill-pattern=s"; def->aliases.push_back("solid_fill_pattern"); - def->default_value = new ConfigOptionEnum(ipRectilinear); - + def->shortcut.push_back("top_infill_pattern"); + def->shortcut.push_back("bottom_infill_pattern"); + def = this->add("external_perimeter_extrusion_width", coFloatOrPercent); def->label = "↳ external"; def->gui_type = "f_enum_open"; @@ -1402,6 +1412,14 @@ PrintConfigDef::PrintConfigDef() def->enum_labels.push_back("default"); def->default_value = new ConfigOptionFloatOrPercent(0, false); + def = this->add("top_infill_pattern", external_fill_pattern); + def->label = "Top"; + def->full_label = "Top infill pattern"; + def->category = "Infill"; + def->tooltip = "Infill pattern for top layers. This only affects the external visible layer, and not its adjacent solid shells."; + def->cli = "top-infill-pattern=s"; + def->default_value = new ConfigOptionEnum(ipRectilinear); + def = this->add("top_solid_infill_speed", coFloatOrPercent); def->label = "↳ top solid"; def->gui_type = "f_enum_open"; @@ -1504,6 +1522,17 @@ DynamicPrintConfig::normalize() { } } + /* + if (this->has("external_fill_pattern")) { + InfillPattern p = this->opt >("external_fill_pattern"); + this->erase("external_fill_pattern"); + if (!this->has("bottom_infill_pattern")) + this->opt >("bottom_infill_pattern", true)->value = p; + if (!this->has("top_infill_pattern")) + this->opt >("top_infill_pattern", true)->value = p; + } + */ + if (!this->has("solid_infill_extruder") && this->has("infill_extruder")) this->option("solid_infill_extruder", true)->setInt(this->option("infill_extruder")->getInt()); diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 5082d31b3..06944cbc3 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -202,10 +202,10 @@ class PrintObjectConfig : public virtual StaticPrintConfig class PrintRegionConfig : public virtual StaticPrintConfig { public: + ConfigOptionEnum bottom_infill_pattern; ConfigOptionInt bottom_solid_layers; ConfigOptionFloat bridge_flow_ratio; ConfigOptionFloat bridge_speed; - ConfigOptionEnum external_fill_pattern; ConfigOptionFloatOrPercent external_perimeter_extrusion_width; ConfigOptionFloatOrPercent external_perimeter_speed; ConfigOptionBool external_perimeters_first; @@ -233,6 +233,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig ConfigOptionFloatOrPercent solid_infill_speed; ConfigOptionBool thin_walls; ConfigOptionFloatOrPercent top_infill_extrusion_width; + ConfigOptionEnum top_infill_pattern; ConfigOptionInt top_solid_layers; ConfigOptionFloatOrPercent top_solid_infill_speed; @@ -242,10 +243,10 @@ class PrintRegionConfig : public virtual StaticPrintConfig } virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { + OPT_PTR(bottom_infill_pattern); OPT_PTR(bottom_solid_layers); OPT_PTR(bridge_flow_ratio); OPT_PTR(bridge_speed); - OPT_PTR(external_fill_pattern); OPT_PTR(external_perimeter_extrusion_width); OPT_PTR(external_perimeter_speed); OPT_PTR(external_perimeters_first); @@ -273,6 +274,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig OPT_PTR(solid_infill_speed); OPT_PTR(thin_walls); OPT_PTR(top_infill_extrusion_width); + OPT_PTR(top_infill_pattern); OPT_PTR(top_solid_infill_speed); OPT_PTR(top_solid_layers); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index cfa0ef3c7..1aebd2c37 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -257,7 +257,8 @@ PrintObject::invalidate_state_by_config_options(const std::vector Date: Sun, 12 Mar 2017 13:10:54 +0100 Subject: [PATCH 27/96] Better overlap for planepath fill patterns --- xs/src/libslic3r/Fill/FillPlanePath.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Fill/FillPlanePath.cpp b/xs/src/libslic3r/Fill/FillPlanePath.cpp index 2b78f24e1..2ab647417 100644 --- a/xs/src/libslic3r/Fill/FillPlanePath.cpp +++ b/xs/src/libslic3r/Fill/FillPlanePath.cpp @@ -49,7 +49,13 @@ void FillPlanePath::_fill_surface_single( } // polylines = intersection_pl(polylines_src, offset((Polygons)expolygon, scale_(0.02))); polylines = intersection_pl(polylines, (Polygons)expolygon); - + + // Extend paths in order to ensure overlap with perimeters + for (Polyline &p : polylines) { + p.extend_start(this->endpoints_overlap); + p.extend_end(this->endpoints_overlap); + } + /* if (1) { require "Slic3r/SVG.pm"; From af46db320f820cc68e692cccf2f83890f4ee1596 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 11:39:17 +0100 Subject: [PATCH 28/96] Make adhesion between brim and object weaker for easier removal. #2230 --- xs/src/libslic3r/Print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 4ad4e4136..85035340e 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -836,7 +836,7 @@ Print::_make_brim() // perimeters because here we're offsetting outwards) append_to(loops, offset2( islands, - flow.scaled_spacing() * (i + 0.5), + flow.scaled_width() + flow.scaled_spacing() * (i - 1.0 + 0.5), flow.scaled_spacing() * -1.0, 100000, ClipperLib::jtSquare From a29a954d780715dcd7165e7d925182a34f6bf54f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 12:41:28 +0100 Subject: [PATCH 29/96] =?UTF-8?q?If=20--print-center=20is=20not=20supplied?= =?UTF-8?q?,=20center=20print=20instead=20of=20the=20centroid=20of=20the?= =?UTF-8?q?=20supplied=20bed=5Fshape=20instead=20of=20defaulting=20to=2010?= =?UTF-8?q?0,100.=C2=A0#2725?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Slic3r/Print/Simple.pm | 11 +++++++++-- slic3r.pl | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/Print/Simple.pm b/lib/Slic3r/Print/Simple.pm index 4fe3eb820..fda229e2f 100644 --- a/lib/Slic3r/Print/Simple.pm +++ b/lib/Slic3r/Print/Simple.pm @@ -45,7 +45,6 @@ has 'status_cb' => ( has 'print_center' => ( is => 'rw', - default => sub { Slic3r::Pointf->new(100,100) }, ); has 'dont_arrange' => ( @@ -82,7 +81,15 @@ sub set_model { $model->duplicate($self->duplicate, $self->_print->config->min_object_distance); } $_->translate(0,0,-$_->bounding_box->z_min) for @{$model->objects}; - $model->center_instances_around_point($self->print_center) if (! $self->dont_arrange); + + if (!$self->dont_arrange) { + my $print_center = $self->print_center; + if (!defined $print_center) { + my $polygon = Slic3r::Polygon->new_scale(@{$self->_print->config->bed_shape}); + $print_center = Slic3r::Pointf->new_unscale(@{ $polygon->centroid }); + } + $model->center_instances_around_point($print_center); + } foreach my $model_object (@{$model->objects}) { $self->_print->auto_assign_extruders($model_object); diff --git a/slic3r.pl b/slic3r.pl index ee9e45214..5ae2e22fa 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -253,7 +253,7 @@ if (@ARGV) { # slicing from command line rotate => deg2rad($opt{rotate} // 0), duplicate => $opt{duplicate} // 1, duplicate_grid => $opt{duplicate_grid} // [1,1], - print_center => $opt{print_center} // Slic3r::Pointf->new(100,100), + print_center => $opt{print_center}, dont_arrange => $opt{dont_arrange} // 0, status_cb => sub { my ($percent, $message) = @_; From 5dfafda77929bdae89e755edc30e1fd5a7651099 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 13:36:53 +0100 Subject: [PATCH 30/96] Take bed_shape into account when arranging parts from command line. #2725 --- lib/Slic3r/Print/Simple.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/Print/Simple.pm b/lib/Slic3r/Print/Simple.pm index fda229e2f..40e6d7e03 100644 --- a/lib/Slic3r/Print/Simple.pm +++ b/lib/Slic3r/Print/Simple.pm @@ -72,20 +72,23 @@ sub set_model { $instance->set_rotation($instance->rotation + $self->rotate); } + my $bed_shape = $self->_print->config->bed_shape; + my $bb = Slic3r::Geometry::BoundingBoxf->new_from_points($bed_shape); + if ($self->duplicate_grid->[X] > 1 || $self->duplicate_grid->[Y] > 1) { $model->duplicate_objects_grid($self->duplicate_grid->[X], $self->duplicate_grid->[Y], $self->_print->config->duplicate_distance); } elsif ($need_arrange) { - $model->duplicate_objects($self->duplicate, $self->_print->config->min_object_distance); + $model->duplicate_objects($self->duplicate, $self->_print->config->min_object_distance, $bb); } elsif ($self->duplicate > 1) { # if all input objects have defined position(s) apply duplication to the whole model - $model->duplicate($self->duplicate, $self->_print->config->min_object_distance); + $model->duplicate($self->duplicate, $self->_print->config->min_object_distance, $bb); } $_->translate(0,0,-$_->bounding_box->z_min) for @{$model->objects}; if (!$self->dont_arrange) { my $print_center = $self->print_center; if (!defined $print_center) { - my $polygon = Slic3r::Polygon->new_scale(@{$self->_print->config->bed_shape}); + my $polygon = Slic3r::Polygon->new_scale(@$bed_shape); $print_center = Slic3r::Pointf->new_unscale(@{ $polygon->centroid }); } $model->center_instances_around_point($print_center); From a49d82691e113d2b242a554e1aa01c6688e7690e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 13:37:25 +0100 Subject: [PATCH 31/96] Only use the supplied bounding box (bed shape) as a hint when auto arranging, and revert to unconstrained arrangement on failure (still better than no arranging at all). #2725 --- xs/src/libslic3r/Model.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 3b02c36d5..ca9c0b227 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -255,13 +255,26 @@ bool Model::_arrange(const Pointfs &sizes, coordf_t dist, const BoundingBoxf* bb, Pointfs &out) const { // we supply unscaled data to arrange() - return Slic3r::Geometry::arrange( + bool result = Slic3r::Geometry::arrange( sizes.size(), // number of parts BoundingBoxf(sizes).max, // width and height of a single cell dist, // distance between cells bb, // bounding box of the area to fill out // output positions ); + + if (!result && bb != NULL) { + // Try to arrange again ignoring bb + result = Slic3r::Geometry::arrange( + sizes.size(), // number of parts + BoundingBoxf(sizes).max, // width and height of a single cell + dist, // distance between cells + NULL, // bounding box of the area to fill + out // output positions + ); + } + + return result; } /* arrange objects preserving their instance count From ff43f9a7f80aa326ae4f29482b0744394c2b54c4 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 13:50:05 +0100 Subject: [PATCH 32/96] When slicing from command line, emit a warning if parts might not fit in the print bed. #2725 --- lib/Slic3r/Print/Simple.pm | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/Slic3r/Print/Simple.pm b/lib/Slic3r/Print/Simple.pm index 40e6d7e03..9087ae0bc 100644 --- a/lib/Slic3r/Print/Simple.pm +++ b/lib/Slic3r/Print/Simple.pm @@ -9,6 +9,7 @@ package Slic3r::Print::Simple; use Moo; use Slic3r::Geometry qw(X Y); +use Slic3r::Geometry::Clipper qw(diff); has '_print' => ( is => 'ro', @@ -56,6 +57,13 @@ has 'output_file' => ( is => 'rw', ); +sub _bed_polygon { + my ($self) = @_; + + my $bed_shape = $self->_print->config->bed_shape; + return Slic3r::Polygon->new_scale(@$bed_shape); +} + sub set_model { # $model is of type Slic3r::Model my ($self, $model) = @_; @@ -86,11 +94,8 @@ sub set_model { $_->translate(0,0,-$_->bounding_box->z_min) for @{$model->objects}; if (!$self->dont_arrange) { - my $print_center = $self->print_center; - if (!defined $print_center) { - my $polygon = Slic3r::Polygon->new_scale(@$bed_shape); - $print_center = Slic3r::Pointf->new_unscale(@{ $polygon->centroid }); - } + my $print_center = $self->print_center + // Slic3r::Pointf->new_unscale(@{ $self->_bed_polygon->centroid }); $model->center_instances_around_point($print_center); } @@ -109,6 +114,13 @@ sub _before_export { sub _after_export { my ($self) = @_; + + # check that all parts fit in bed shape, and warn if they don't + # TODO: use actual toolpaths instead of total bounding box + if (@{diff([$self->_print->bounding_box->polygon], [$self->_bed_polygon])}) { + warn "Warning: the supplied parts might not fit in the configured bed shape. " + . "You might want to review the result before printing.\n"; + } $self->_print->set_status_cb(undef); } From 3e8e0ec02fdf17ba07cf41f5abb5faa7c5e92d81 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 15:06:11 +0100 Subject: [PATCH 33/96] Fixed regression in Simple Mode --- lib/Slic3r/GUI/SimpleTab.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GUI/SimpleTab.pm b/lib/Slic3r/GUI/SimpleTab.pm index 13c6efc88..6e7d00d09 100644 --- a/lib/Slic3r/GUI/SimpleTab.pm +++ b/lib/Slic3r/GUI/SimpleTab.pm @@ -122,7 +122,7 @@ sub build { $self->init_config_options(qw( layer_height perimeters top_solid_layers bottom_solid_layers - fill_density fill_pattern external_fill_pattern + fill_density fill_pattern top_infill_pattern bottom_infill_pattern support_material support_material_spacing raft_layers support_material_contact_distance dont_support_bridges perimeter_speed infill_speed travel_speed @@ -147,7 +147,8 @@ sub build { my $optgroup = $self->new_optgroup('Infill'); $optgroup->append_single_option_line('fill_density'); $optgroup->append_single_option_line('fill_pattern'); - $optgroup->append_single_option_line('external_fill_pattern'); + $optgroup->append_single_option_line('top_infill_pattern'); + $optgroup->append_single_option_line('bottom_infill_pattern'); } { @@ -191,7 +192,7 @@ sub _update { $self->get_field($_)->toggle($have_infill) for qw(fill_pattern); $self->get_field($_)->toggle($have_solid_infill) - for qw(external_fill_pattern); + for qw(top_infill_pattern bottom_infill_pattern); $self->get_field($_)->toggle($have_infill || $have_solid_infill) for qw(infill_speed); From 662031bc2d6a49d1c3f09bb96e5e3512d51cddb7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 23:47:52 +0100 Subject: [PATCH 34/96] Print the brim using the support material extruder if we have a raft. #2957 --- lib/Slic3r/Print/GCode.pm | 6 +++++- t/skirt_brim.t | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index b851f5242..b2187f208 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -462,7 +462,11 @@ sub process_layer { # extrude brim if (!$self->_brim_done) { - $gcode .= $self->_gcodegen->set_extruder($self->print->regions->[0]->config->perimeter_extruder-1); + my $extr = $self->print->regions->[0]->config->perimeter_extruder-1; + if (my $o = first { $_->config->raft_layers > 0 } @{$self->objects}) { + $extr = $o->config->support_material_extruder-1; + } + $gcode .= $self->_gcodegen->set_extruder($extr); $self->_gcodegen->set_origin(Slic3r::Pointf->new(0,0)); $self->_gcodegen->avoid_crossing_perimeters->set_use_external_mp(1); $gcode .= $self->_gcodegen->extrude($_, 'brim', $object->config->support_material_speed) diff --git a/t/skirt_brim.t b/t/skirt_brim.t index 9b2a0a126..d6181ba23 100644 --- a/t/skirt_brim.t +++ b/t/skirt_brim.t @@ -1,4 +1,4 @@ -use Test::More tests => 6; +use Test::More tests => 8; use strict; use warnings; @@ -89,6 +89,39 @@ use Slic3r::Test; ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt_height = 0 and skirts > 0'; } +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('skirts', 0); + $config->set('brim_width', 5); + $config->set('perimeter_extruder', 2); + $config->set('support_material_extruder', 3); + + my $test = sub { + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + my $tool = undef; + my $brim_tool = undef; + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if ($cmd =~ /^T(\d+)/) { + $tool = $1; + } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) { + if (!defined $brim_tool) { + # first extrusion is brim + $brim_tool = $tool; + } + } + }); + return $brim_tool; + }; + is $test->(), $config->perimeter_extruder-1, + 'brim is printed with the extruder used for the perimeters of first object'; + + $config->set('raft_layers', 1); + is $test->(), $config->support_material_extruder-1, + 'if raft is enabled, brim is printed with the extruder used for it'; +} + { my $config = Slic3r::Config->new_from_defaults; $config->set('layer_height', 0.4); From c93314c8fed65c68440d061d7bab49705e203c3c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 14 Mar 2017 01:32:37 +0100 Subject: [PATCH 35/96] Bugfix: wrong extruder order when more than 10 extruders were used. #3235 --- lib/Slic3r/Print/GCode.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index b2187f208..bd0701437 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -582,7 +582,7 @@ sub process_layer { } # tweak extruder ordering to save toolchanges - my @extruders = sort keys %by_extruder; + my @extruders = sort { $a <=> $b } keys %by_extruder; if (@extruders > 1) { my $last_extruder_id = $self->_gcodegen->writer->extruder->id; if (exists $by_extruder{$last_extruder_id}) { From 4b4885fcdf67ebf1b2b59fdf635e25551cf83db4 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 14 Mar 2017 16:45:49 +0100 Subject: [PATCH 36/96] Remove warning when calling flowrate.pl without env variables --- utils/post-processing/flowrate.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/post-processing/flowrate.pl b/utils/post-processing/flowrate.pl index 7aeef24dc..ac09d5e9a 100755 --- a/utils/post-processing/flowrate.pl +++ b/utils/post-processing/flowrate.pl @@ -23,7 +23,7 @@ while (<>) { my $dist = sqrt( (($x-$X)**2) + (($y-$Y)**2) ); if ($dist > 0) { my $mm_per_mm = $e_length / $dist; # dE/dXY - my $mm3_per_mm = ($filament_diameter[$T] ** 2) * PI/4 * $mm_per_mm; + my $mm3_per_mm = (($filament_diameter[$T] // 0) ** 2) * PI/4 * $mm_per_mm; my $vol_speed = $F/60 * $mm3_per_mm; my $comment = sprintf ' ; dXY = %.3fmm ; dE = %.5fmm ; dE/XY = %.5fmm/mm; volspeed = %.5fmm^3/sec', $dist, $e_length, $mm_per_mm, $vol_speed; From 53fee674897adcc65c0514464865ef679543367b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 14 Mar 2017 16:46:11 +0100 Subject: [PATCH 37/96] New experimental option z_steps_per_mm. #1827 --- lib/Slic3r/GUI/Tab.pm | 3 ++- lib/Slic3r/Print/Object.pm | 19 ++++++++++++++++--- slic3r.pl | 2 ++ xs/src/libslic3r/PrintConfig.cpp | 6 ++++++ xs/src/libslic3r/PrintConfig.hpp | 2 ++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index c6190ea4d..1b61e3f38 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -1084,7 +1084,7 @@ sub build { my (%params) = @_; $self->init_config_options(qw( - bed_shape z_offset has_heatbed + bed_shape z_offset z_steps_per_mm has_heatbed gcode_flavor use_relative_e_distances serial_port serial_speed octoprint_host octoprint_apikey @@ -1233,6 +1233,7 @@ sub build { $optgroup->append_single_option_line('use_volumetric_e'); $optgroup->append_single_option_line('pressure_advance'); $optgroup->append_single_option_line('vibration_limit'); + $optgroup->append_single_option_line('z_steps_per_mm'); } } { diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 8dbefc117..1271da121 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -33,6 +33,17 @@ sub support_layers { return [ map $self->get_support_layer($_), 0..($self->support_layer_count - 1) ]; } +sub _adjust_layer_height { + my ($self, $lh) = @_; + + if ($self->print->config->z_steps_per_mm > 0) { + my $min_dz = 1/$self->print->config->z_steps_per_mm * 4; + $lh = int($lh / $min_dz + 0.5) * $min_dz; + } + + return $lh; +} + # 1) Decides Z positions of the layers, # 2) Initializes layers and their regions # 3) Slices the object meshes @@ -52,8 +63,10 @@ sub slice { { my @nozzle_diameters = map $self->print->config->get_at('nozzle_diameter', $_), @{$self->print->object_extruders}; - - $self->config->set('layer_height', min(@nozzle_diameters, $self->config->layer_height)); + + my $lh = min(@nozzle_diameters, $self->config->layer_height); + + $self->config->set('layer_height', $self->_adjust_layer_height($lh)); } # init layers @@ -113,7 +126,7 @@ sub slice { # look for an applicable custom range if (my $range = first { $_->[0] <= $slice_z && $_->[1] > $slice_z } @{$self->layer_height_ranges}) { - $height = $range->[2]; + $height = $self->_adjust_layer_height($range->[2]); # if user set custom height to zero we should just skip the range and resume slicing over it if ($height == 0) { diff --git a/slic3r.pl b/slic3r.pl index 5ae2e22fa..d4ebd5c48 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -347,6 +347,8 @@ $j (default: 100,100) --z-offset Additional height in mm to add to vertical coordinates (+/-, default: $config->{z_offset}) + --z-steps-per-mm Number of full steps per mm of the Z axis. Experimental feature for + preventing rounding issues. --gcode-flavor The type of G-code to generate (reprap/teacup/repetier/makerware/sailfish/mach3/machinekit/smoothie/no-extrusion, default: $config->{gcode_flavor}) --use-relative-e-distances Enable this to get relative E values (default: no) diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 99713270c..caeaaf8da 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1501,6 +1501,12 @@ PrintConfigDef::PrintConfigDef() def->sidetext = "mm"; def->cli = "z-offset=f"; def->default_value = new ConfigOptionFloat(0); + + def = this->add("z_steps_per_mm", coFloat); + def->label = "Z full steps/mm"; + def->tooltip = "Set this to the number of *full* steps (not microsteps) needed for moving the Z axis by 1mm; you can calculate this by dividing the number of microsteps configured in your firmware by the microstepping amount (8, 16, 32). Slic3r will round your configured layer height to the nearest multiple of that value in order to ensure the best accuracy. This is most useful for machines with imperial leadscrews or belt-driven Z or for unusual layer heights with metric leadscrews. Set to zero to disable this experimental feature."; + def->cli = "z-steps-per-mm=f"; + def->default_value = new ConfigOptionFloat(0); } PrintConfigDef print_config_def; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 06944cbc3..bd63bb919 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -427,6 +427,7 @@ class PrintConfig : public GCodeConfig ConfigOptionFloat vibration_limit; ConfigOptionBools wipe; ConfigOptionFloat z_offset; + ConfigOptionFloat z_steps_per_mm; PrintConfig(bool initialize = true) : GCodeConfig(false) { if (initialize) @@ -488,6 +489,7 @@ class PrintConfig : public GCodeConfig OPT_PTR(vibration_limit); OPT_PTR(wipe); OPT_PTR(z_offset); + OPT_PTR(z_steps_per_mm); // look in parent class ConfigOption* opt; From 8fe15d0162b703e94d2f38cb43c790d579fe2169 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 14 Mar 2017 17:26:27 +0100 Subject: [PATCH 38/96] Adjust the top layer thickness in order to match the original object height. #2978 --- lib/Slic3r/Print/Object.pm | 33 +++++++++++++++++++++++++++++++-- xs/src/libslic3r/Print.cpp | 3 ++- xs/xsp/Layer.xsp | 4 ++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 1271da121..ba6bb62b7 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -60,11 +60,13 @@ sub slice { $self->set_step_started(STEP_SLICE); $self->print->status_cb->(10, "Processing triangulated mesh"); + my $min_nozzle_diameter; { my @nozzle_diameters = map $self->print->config->get_at('nozzle_diameter', $_), @{$self->print->object_extruders}; - my $lh = min(@nozzle_diameters, $self->config->layer_height); + $min_nozzle_diameter = min(@nozzle_diameters); + my $lh = min($min_nozzle_diameter, $self->config->layer_height); $self->config->set('layer_height', $self->_adjust_layer_height($lh)); } @@ -142,7 +144,8 @@ sub slice { $print_z += $height; $slice_z += $height/2; - + last if $slice_z > $max_z; + ### Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z; $self->add_layer($id, $height, $print_z, $slice_z); @@ -157,6 +160,32 @@ sub slice { } } + # Reduce or thicken the top layer in order to match the original object size. + # This is not actually related to z_steps_per_mm but we only enable it in case + # user provided that value, as it means they really care about the layer height + # accuracy and we don't provide unexpected result for people noticing the last + # layer has a different layer height. + if ($self->print->config->z_steps_per_mm > 0) { + my $first_object_layer = $self->get_layer(0); + my $last_object_layer = $self->get_layer($self->layer_count-1); + my $print_height = $last_object_layer->print_z - $first_object_layer->print_z + $first_object_layer->height; + my $diff = $print_height - unscale($self->size->z); + if ($diff < 0) { + # we need to thicken last layer + $diff = min(abs($diff), $min_nozzle_diameter - $last_object_layer->height); + $last_object_layer->set_height($last_object_layer->height + $diff); + $last_object_layer->set_print_z($last_object_layer->print_z + $diff); + } else { + # we need to reduce last layer + # prevent generation of a too small layer + my $new_height = $last_object_layer->height - $diff; + if ($new_height < $min_nozzle_diameter/2) { + $last_object_layer->set_height($new_height); + $last_object_layer->set_print_z($last_object_layer->print_z - $diff); + } + } + } + # make sure all layers contain layer region objects for all regions my $regions_count = $self->print->region_count; foreach my $layer (@{ $self->layers }) { diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 85035340e..f7c722265 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -166,7 +166,8 @@ Print::invalidate_state_by_config_options(const std::vector steps.insert(psBrim); steps.insert(psSkirt); } else if (*opt_key == "nozzle_diameter" - || *opt_key == "resolution") { + || *opt_key == "resolution" + || *opt_key == "z_steps_per_mm") { osteps.insert(posSlice); } else if (*opt_key == "avoid_crossing_perimeters" || *opt_key == "bed_shape" diff --git a/xs/xsp/Layer.xsp b/xs/xsp/Layer.xsp index 4be9feccf..97569854e 100644 --- a/xs/xsp/Layer.xsp +++ b/xs/xsp/Layer.xsp @@ -56,6 +56,10 @@ %code%{ RETVAL = THIS->print_z; %}; coordf_t height() %code%{ RETVAL = THIS->height; %}; + void set_print_z(coordf_t z) + %code%{ THIS->print_z = z; %}; + void set_height(coordf_t h) + %code%{ THIS->height = h; %}; void set_upper_layer(Layer *layer) %code%{ THIS->upper_layer = layer; %}; From c20d44c3887c39eaa6850470ba6571d7c92ab336 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 14 Mar 2017 17:30:26 +0100 Subject: [PATCH 39/96] Replaced emplace() as the Windows build server doesn't support it now --- xs/src/libslic3r/Config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 1f366f3cb..ccb357cf2 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -217,7 +217,7 @@ ConfigDef::add(const t_config_option_key &opt_key, ConfigOptionType type) ConfigOptionDef* ConfigDef::add(const t_config_option_key &opt_key, const ConfigOptionDef &def) { - this->options.emplace(opt_key, def); + this->options.insert(std::make_pair(opt_key, def)); return &this->options[opt_key]; } From d73e8558a26899b4eb13367eb40346dd6827f802 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 9 Jan 2017 10:44:11 +0100 Subject: [PATCH 40/96] Added AGPLv3 license text --- LICENSE | 661 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 661 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..dba13ed2d --- /dev/null +++ b/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. From cdf48ade2588e01c217e23391e356a580657ed47 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 16 Mar 2017 11:10:23 +0100 Subject: [PATCH 41/96] Fix a typo in the BOOST_* environment variables and clarify the error message. Also, support GCC 4.6.x. --- xs/Build.PL | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/xs/Build.PL b/xs/Build.PL index 12837630e..87ba0c1ef 100644 --- a/xs/Build.PL +++ b/xs/Build.PL @@ -15,13 +15,18 @@ my $mswin = $^O eq 'MSWin32'; # HAS_BOOL : stops Perl/lib/CORE/handy.h from doing "# define bool char" for MSVC # NOGDI : prevents inclusion of wingdi.h which defines functions Polygon() and Polyline() in global namespace # BOOST_ASIO_DISABLE_KQUEUE : prevents a Boost ASIO bug on OS X: https://svn.boost.org/trac/boost/ticket/5339 -# std=c++11 Enforce usage of C++11 (required now). Minimum compiler supported: gcc 4.9, clang 3.3, MSVC 14.0 -my @cflags = qw(-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DSLIC3RXS -DBOOST_ASIO_DISABLE_KQUEUE - -std=c++11); +my @cflags = qw(-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DSLIC3RXS -DBOOST_ASIO_DISABLE_KQUEUE); if ($cpp_guess->is_gcc) { # GCC is pedantic with c++11 std, so undefine strict ansi to get M_PI back push @cflags, qw(-U__STRICT_ANSI__); } +if (`$Config{cc} -v` =~ /gcc version 4\.6\./) { + # Compatibility with GCC 4.6 is not a requirement, but as long as code compiles on it we try to support it. + push @cflags, qw(-std=c++0x); +} else { + # std=c++11 Enforce usage of C++11 (required now). Minimum compiler supported: gcc 4.9, clang 3.3, MSVC 14.0 + push @cflags, qw(-std=c++11); +} my @ldflags = (); if ($^O eq 'darwin') { push @cflags, qw(-stdlib=libc++); @@ -75,8 +80,8 @@ if (defined $ENV{BOOST_INCLUDEDIR}) { } my @boost_libs = (); -if (defined $ENV{BOOST_LIBRARYDIR}) { - push @boost_libs, $ENV{BOOST_LIBRARYDIR} +if (defined $ENV{BOOST_LIBRARYPATH}) { + push @boost_libs, $ENV{BOOST_LIBRARYPATH} } elsif (defined $ENV{BOOST_DIR}) { my $subdir = $ENV{BOOST_DIR} . ($mswin ? '\stage\lib' : '/stage/lib'); if (-d $subdir) { @@ -154,12 +159,12 @@ Slic3r requires the Boost libraries. Please make sure they are installed. If they are installed, this script should be able to locate them in several standard locations. If this is not the case, you might want to supply their -path through the BOOST_DIR environment variable: +path through the BOOST_INCLUDEPATH and BOOST_LIBRARYPATH environment variables: - BOOST_DIR=/path/to/boost perl Build.PL + BOOST_INCLUDEPATH=/usr/local/include BOOST_LIBRARYPATH=/usr/lib perl Build.PL -Or you may specify BOOST_INCLUDEPATH and BOOST_LIBRARYPATH separatly, which -is handy, if you have built Boost libraries with mutliple settings. +If you just compiled Boost in its source directory without installing it in the +system you can just provide the BOOST_DIR variable pointing to that directory. EOF From f724090d293ff9c3519be68f66ba42eed7839237 Mon Sep 17 00:00:00 2001 From: Paul Novak Date: Thu, 16 Mar 2017 19:38:10 -0700 Subject: [PATCH 42/96] Use default size for label and size column label to fit content. --- lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm b/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm index d7909816b..c0979cd13 100644 --- a/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm @@ -77,7 +77,7 @@ sub new { { my $label = Wx::StaticText->new($self, -1, "You can use this section to override the default layer height for parts of this object. Set layer height to zero to skip portions of the input file.", - wxDefaultPosition, [-1, 40]); + wxDefaultPosition, wxDefaultSize); $label->SetFont(Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); $sizer->Add($label, 0, wxEXPAND | wxALL, 10); } @@ -90,7 +90,7 @@ sub new { $grid->SetColLabelValue(0, "Min Z (mm)"); $grid->SetColLabelValue(1, "Max Z (mm)"); $grid->SetColLabelValue(2, "Layer height (mm)"); - $grid->SetColSize($_, 135) for 0..2; + $grid->SetColSize($_, -1) for 0..2; $grid->SetDefaultCellAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE); # load data From b50417cb2072027cea9b6a44a9ac15f3bc08a4ad Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 16:03:58 +0100 Subject: [PATCH 43/96] Cosmetic improvements --- lib/Slic3r/GUI/Plater.pm | 26 ++++++++++++++++++-------- lib/Slic3r/GUI/Tab.pm | 14 +++++++------- var/script.png | Bin 0 -> 748 bytes xs/src/libslic3r/PrintConfig.cpp | 4 ++-- 4 files changed, 27 insertions(+), 17 deletions(-) create mode 100755 var/script.png diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 3ce193a7c..d8d11f3e2 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -435,7 +435,7 @@ sub new { my $print_info_sizer; { - my $box = Wx::StaticBox->new($self, -1, "Sliced Info"); + my $box = Wx::StaticBox->new($self, -1, "Print Summary"); $print_info_sizer = Wx::StaticBoxSizer->new($box, wxVERTICAL); $print_info_sizer->SetMinSize([350,-1]); my $grid_sizer = Wx::FlexGridSizer->new(2, 2, 5, 5); @@ -444,9 +444,7 @@ sub new { $grid_sizer->AddGrowableCol(3, 1); $print_info_sizer->Add($grid_sizer, 0, wxEXPAND); my @info = ( - fil_cm => "Used Filament (cm)", - fil_cm3 => "Used Filament (cm^3)", - fil_g => "Used Filament (g)", + fil => "Used Filament", cost => "Cost", ); while (my $field = shift @info) { @@ -1398,10 +1396,22 @@ sub on_export_completed { $self->send_gcode if $send_gcode; $self->{print_file} = undef; $self->{send_gcode_file} = undef; - $self->{"print_info_cost"}->SetLabel(sprintf("%.2f" , $self->{print}->total_cost)); - $self->{"print_info_fil_g"}->SetLabel(sprintf("%.2f" , $self->{print}->total_weight)); - $self->{"print_info_fil_cm3"}->SetLabel(sprintf("%.2f" , $self->{print}->total_extruded_volume) / 1000); - $self->{"print_info_fil_cm"}->SetLabel(sprintf("%.2f" , $self->{print}->total_used_filament) / 10); + + { + my $fil = sprintf( + '%.2fcm (%.2fcm³%s)', + $self->{print}->total_used_filament / 10, + $self->{print}->total_extruded_volume / 1000, + $self->{print}->total_weight + ? sprintf(', %.2fg', $self->{print}->total_weight) + : '', + ); + my $cost = $self->{print}->total_cost + ? sprintf("%.2f" , $self->{print}->total_cost) + : 'n.a.'; + $self->{print_info_fil}->SetLabel($fil); + $self->{print_info_cost}->SetLabel($cost); + } # this updates buttons status $self->object_list_changed; diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 1b61e3f38..6f772d2b7 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -916,12 +916,7 @@ sub build { $optgroup->append_single_option_line('filament_colour', 0); $optgroup->append_single_option_line('filament_diameter', 0); $optgroup->append_single_option_line('extrusion_multiplier', 0); - $optgroup->append_single_option_line('filament_density', 0); - $optgroup->append_single_option_line('filament_cost', 0); } - - - { my $optgroup = $page->new_optgroup('Temperature (°C)'); @@ -943,6 +938,11 @@ sub build { $optgroup->append_line($line); } } + { + my $optgroup = $page->new_optgroup('Optional information'); + $optgroup->append_single_option_line('filament_density', 0); + $optgroup->append_single_option_line('filament_cost', 0); + } } { @@ -1008,7 +1008,7 @@ sub build { } } { - my $page = $self->add_options_page('Custom G-code', 'cog.png'); + my $page = $self->add_options_page('Custom G-code', 'script.png'); { my $optgroup = $page->new_optgroup('Start G-code', label_width => 0, @@ -1237,7 +1237,7 @@ sub build { } } { - my $page = $self->add_options_page('Custom G-code', 'cog.png'); + my $page = $self->add_options_page('Custom G-code', 'script.png'); { my $optgroup = $page->new_optgroup('Start G-code', label_width => 0, diff --git a/var/script.png b/var/script.png new file mode 100755 index 0000000000000000000000000000000000000000..0f9ed4d48301ffdce04cdb17dbf8acbad8372d11 GIT binary patch literal 748 zcmVrG{ z$cl-P=->hx6#}NAmbP5myY~I>{qOhtLMa7Y{qE64eE#g}(xpY)TeQ8l?;Upi4EuP3 zj9qNwYy4OP^j-JLi)W5q`snr30AQZ_=_2*h-J^Uqwd^<9gC_@m_YruehOwSPa9@O%#PST ztn>RnbQXoQ3&2p_*N2(YI zkrMO}==(rnxsJAW59QQs0L07JZk*~;x_q%%{cN7dr3j%I4jC^oS!R20 zp-X8Kpw211iFbazd*AM1?Vu^zTr_Qvx?Y!ieJR$aQy;v2#^ddUoYEFRo!j>1ci(tn z{K@;T0)Sj-bCEg}zP!0%dBFa`LT=k_fI7GB{l`yczPWYR>anra$&%HTk?G3F@#Ue> zFdEg-dzaUZYPNRv<+lA7pzgcw+uL{UoxOeM-g%tFNu0n5OqYg(!P3&eWMyo1vh4Ri e9{q`*0R9JiiaRV3rbYDt0000add("filament_density", coFloats); def->label = "Density"; def->tooltip = "Enter your filament density here. This is only for statistical information. A decent way is to weigh a known length of filament and compute the ratio of the length to volume. Better is to calculate the volume directly through displacement."; - def->sidetext = "g/cm^3"; + def->sidetext = "g/cm³"; def->cli = "filament-density=f@"; def->min = 0; { @@ -909,7 +909,7 @@ PrintConfigDef::PrintConfigDef() def->default_value = new ConfigOptionFloat(4); def = this->add("resolution", coFloat); - def->label = "Resolution"; + def->label = "Resolution (deprecated)"; def->tooltip = "Minimum detail resolution, used to simplify the input file for speeding up the slicing job and reducing memory usage. High-resolution models often carry more detail than printers can render. Set to zero to disable any simplification and use full resolution from input."; def->sidetext = "mm"; def->cli = "resolution=f"; From a1c7b65741be6b0a889567db0f434fe2f6969e42 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 16:41:34 +0100 Subject: [PATCH 44/96] Moved threads option from print settings to application preferences --- lib/Slic3r/GUI.pm | 20 ++++++++++---------- lib/Slic3r/GUI/Plater.pm | 4 ++++ lib/Slic3r/GUI/Preferences.pm | 7 +++++++ lib/Slic3r/GUI/Tab.pm | 3 +-- lib/Slic3r/Print/Simple.pm | 2 +- slic3r.pl | 5 ++++- xs/src/libslic3r/PrintConfig.cpp | 1 - xs/src/libslic3r/PrintConfig.hpp | 2 ++ 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index c4fe92a04..aea900028 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -60,6 +60,7 @@ our $no_controller; our $no_plater; our $mode; our $autosave; +our $threads; our @cb; our $Settings = { @@ -70,8 +71,8 @@ our $Settings = { invert_zoom => 0, background_processing => 0, # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. - # By default, Prusa has the controller hidden. - no_controller => 1, + no_controller => 0, + threads => $Slic3r::Config::Options->{threads}{default}, }, }; @@ -121,16 +122,15 @@ sub OnInit { my $last_version; if (-f "$enc_datadir/slic3r.ini") { my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") }; - $Settings = $ini if $ini; - $last_version = $Settings->{_}{version}; - $Settings->{_}{mode} ||= 'expert'; - $Settings->{_}{autocenter} //= 1; - $Settings->{_}{invert_zoom} //= 0; - $Settings->{_}{background_processing} //= 1; - # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. - $Settings->{_}{no_controller} //= 1; + if ($ini) { + $last_version = $ini->{_}{version}; + $ini->{_}{$_} = $Settings->{_}{$_} + for grep !exists $ini->{_}{$_}, keys %{$Settings->{_}}; + $Settings = $ini; + } } $Settings->{_}{version} = $Slic3r::VERSION; + $Settings->{_}{threads} = $threads if $threads; $self->save_settings; # application frame diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index d8d11f3e2..c62067371 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1157,6 +1157,10 @@ sub start_background_process { return; } + if ($Slic3r::GUI::Settings->{_}{threads}) { + $self->{print}->config->set('threads', $Slic3r::GUI::Settings->{_}{threads}); + } + # start thread @_ = (); $self->{process_thread} = Slic3r::spawn_thread(sub { diff --git a/lib/Slic3r/GUI/Preferences.pm b/lib/Slic3r/GUI/Preferences.pm index 91465fa64..231eb5cc9 100644 --- a/lib/Slic3r/GUI/Preferences.pm +++ b/lib/Slic3r/GUI/Preferences.pm @@ -67,6 +67,13 @@ sub new { default => $Slic3r::GUI::Settings->{_}{background_processing}, readonly => !$Slic3r::have_threads, )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'threads', + type => 'i', + label => 'Threads', + tooltip => $Slic3r::Config::Options->{threads}{tooltip}, + default => $Slic3r::GUI::Settings->{_}{threads}, + )); $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( opt_id => 'no_controller', type => 'bool', diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 6f772d2b7..a19bb1e76 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -497,7 +497,7 @@ sub build { external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width top_infill_extrusion_width support_material_extrusion_width infill_overlap bridge_flow_ratio - xy_size_compensation threads resolution + xy_size_compensation resolution )); $self->{config}->set('print_settings_id', ''); @@ -686,7 +686,6 @@ sub build { { my $optgroup = $page->new_optgroup('Other'); $optgroup->append_single_option_line('xy_size_compensation'); - $optgroup->append_single_option_line('threads') if $Slic3r::have_threads; $optgroup->append_single_option_line('resolution'); } } diff --git a/lib/Slic3r/Print/Simple.pm b/lib/Slic3r/Print/Simple.pm index 9087ae0bc..26f1d4383 100644 --- a/lib/Slic3r/Print/Simple.pm +++ b/lib/Slic3r/Print/Simple.pm @@ -14,7 +14,7 @@ use Slic3r::Geometry::Clipper qw(diff); has '_print' => ( is => 'ro', default => sub { Slic3r::Print->new }, - handles => [qw(apply_config extruders output_filepath + handles => [qw(apply_config config extruders output_filepath total_used_filament total_extruded_volume placeholder_parser process)], ); diff --git a/slic3r.pl b/slic3r.pl index d4ebd5c48..69bb58593 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -29,6 +29,7 @@ my %cli_options = (); 'debug' => \$Slic3r::debug, 'gui' => \$opt{gui}, 'o|output=s' => \$opt{output}, + 'j|threads=i' => \$opt{threads}, 'save=s' => \$opt{save}, 'load=s@' => \$opt{load}, @@ -109,6 +110,7 @@ if ((!@ARGV || $opt{gui}) && !$opt{save} && eval "require Slic3r::GUI; 1") { $Slic3r::GUI::no_plater = $opt{no_plater}; $Slic3r::GUI::mode = $opt{gui_mode}; $Slic3r::GUI::autosave = $opt{autosave}; + $Slic3r::GUI::threads = $opt{threads}; } $gui = Slic3r::GUI->new; setlocale(LC_NUMERIC, 'C'); @@ -263,6 +265,7 @@ if (@ARGV) { # slicing from command line ); $sprint->apply_config($config); + $sprint->config->set('threads', $opt{threads}) if $opt{threads}; $sprint->set_model($model); if ($opt{export_svg}) { @@ -293,7 +296,7 @@ sub usage { my $j = ''; if ($Slic3r::have_threads) { $j = <<"EOF"; - -j, --threads Number of threads to use (1+, default: $config->{threads}) + -j, --threads Number of threads to use EOF } diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 586661510..1766f63cd 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1383,7 +1383,6 @@ PrintConfigDef::PrintConfigDef() def = this->add("threads", coInt); def->label = "Threads"; def->tooltip = "Threads are used to parallelize long-running tasks. Optimal threads number is slightly above the number of available cores/processors."; - def->cli = "threads|j=i"; def->readonly = true; def->min = 1; { diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index bd63bb919..2ea423d8c 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -624,6 +624,7 @@ class CLIConfig ConfigOptionString save; ConfigOptionFloat scale; ConfigOptionPoint3 scale_to_fit; + ConfigOptionBool threads; CLIConfig() : ConfigBase(), StaticConfig() { this->def = &cli_config_def; @@ -647,6 +648,7 @@ class CLIConfig OPT_PTR(save); OPT_PTR(scale); OPT_PTR(scale_to_fit); + OPT_PTR(threads); return NULL; }; From 33059e18d7945625a5cecd646dd5b642291ed61e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 16:44:09 +0100 Subject: [PATCH 45/96] Change the logic used for enabling version checks so that it's compatible with the new packaging method --- lib/Slic3r/GUI.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index aea900028..7d2f7f26b 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -297,7 +297,7 @@ sub have_version_check { my ($self) = @_; # return an explicit 0 - return ($Slic3r::have_threads && $Slic3r::build && $have_LWP) || 0; + return ($Slic3r::have_threads && $Slic3r::VERSION !~ /-dev$/ && $have_LWP) || 0; } sub check_version { From 8067295684181dd5b6ddc94d306aaf027f6f70ca Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 16:45:35 +0100 Subject: [PATCH 46/96] Check number of skirt loops before disabling spiral vase --- lib/Slic3r/Print/GCode.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index bd0701437..635a4b65f 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -326,7 +326,8 @@ sub process_layer { $self->_spiral_vase->enable( ($layer->id > 0 || $self->print->config->brim_width == 0 || $self->print->config->interior_brim_width == 0 || $self->print->config->brim_connections_width == 0) - && ($layer->id >= $self->print->config->skirt_height && !$self->print->has_infinite_skirt) + && ($self->print->config->skirts == 0 + || ($layer->id >= $self->print->config->skirt_height && !$self->print->has_infinite_skirt)) && !defined(first { $_->region->config->bottom_solid_layers > $layer->id } @{$layer->regions}) && !defined(first { $_->perimeters->items_count > 1 } @{$layer->regions}) && !defined(first { $_->fills->items_count > 0 } @{$layer->regions}) From 5cc509f3fee77307cf4c128f39fca39b3de3c96b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 16:55:29 +0100 Subject: [PATCH 47/96] Try to autodetect HAS_VBO. #3772 --- lib/Slic3r/GUI/3DScene.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 0e6ba3c8f..67046853f 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -50,7 +50,7 @@ use constant PI => 3.1415927; # Constant to determine if Vertex Buffer objects are used to draw # bed grid and the cut plane for object separation. -use constant HAS_VBO => 1; +use constant HAS_VBO => eval { glGenBuffersARB_p(0); 1 }; # phi / theta angles to orient the camera. From 94ed08c14d62b2fc7e1427ef272d1be42a486fc7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 17:13:53 +0100 Subject: [PATCH 48/96] Make width and speed options readable again in the override panel --- xs/src/libslic3r/PrintConfig.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 1766f63cd..10efc1b6c 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -210,6 +210,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("external_perimeter_extrusion_width", coFloatOrPercent); def->label = "↳ external"; + def->full_label = "External perimeters extrusion width"; def->gui_type = "f_enum_open"; def->category = "Extrusion Width"; def->tooltip = "Set this to a non-zero value to set a manual extrusion width for external perimeters. If auto is chosen, a value will be used that maximizes accuracy of the external visible surfaces. If expressed as percentage (for example 200%) it will be computed over layer height."; @@ -222,6 +223,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("external_perimeter_speed", coFloatOrPercent); def->label = "↳ external"; + def->full_label = "External perimeters speed"; def->gui_type = "f_enum_open"; def->category = "Speed"; def->tooltip = "This separate setting will affect the speed of external perimeters (the visible ones). If expressed as percentage (for example: 80%) it will be calculated on the perimeters speed setting above."; @@ -458,6 +460,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("fill_gaps", coBool); def->label = "Fill gaps"; + def->category = "Infill"; def->tooltip = "If this is enabled, gaps will be filled with single passes. Enable this for better quality, disable it for shorter printing times."; def->cli = "fill-gaps!"; def->default_value = new ConfigOptionBool(true); @@ -554,6 +557,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("gap_fill_speed", coFloat); def->label = "↳ gaps"; + def->full_label = "Gap fill speed"; def->gui_type = "f_enum_open"; def->category = "Speed"; def->tooltip = "Speed for filling gaps. Since these are usually single lines you might want to use a low speed for better sticking. If expressed as percentage (for example: 80%) it will be calculated on the infill speed setting above."; @@ -1102,6 +1106,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("small_perimeter_speed", coFloatOrPercent); def->label = "↳ small"; + def->full_label = "Small perimeters speed"; def->gui_type = "f_enum_open"; def->category = "Speed"; def->tooltip = "This separate setting will affect the speed of perimeters having radius <= 6.5mm (usually holes). If expressed as percentage (for example: 80%) it will be calculated on the perimeters speed setting above."; @@ -1141,6 +1146,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("solid_infill_extrusion_width", coFloatOrPercent); def->label = "↳ solid"; + def->full_label = "Solid infill extrusion width"; def->gui_type = "f_enum_open"; def->category = "Extrusion Width"; def->tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for solid surfaces. If expressed as percentage (for example 90%) it will be computed over layer height."; @@ -1153,6 +1159,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("solid_infill_speed", coFloatOrPercent); def->label = "↳ solid"; + def->full_label = "Solid infill speed"; def->gui_type = "f_enum_open"; def->category = "Speed"; def->tooltip = "Speed for printing solid regions (top/bottom/internal horizontal shells). This can be expressed as a percentage (for example: 80%) over the default infill speed above."; @@ -1299,6 +1306,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("support_material_interface_speed", coFloatOrPercent); def->label = "↳ interface"; + def->category = "Support material interface speed"; def->gui_type = "f_enum_open"; def->category = "Support material"; def->tooltip = "Speed for printing support material interface layers. If expressed as percentage (for example 50%) it will be calculated over support material speed."; @@ -1401,6 +1409,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("top_infill_extrusion_width", coFloatOrPercent); def->label = "↳ top solid"; + def->full_label = "Top solid infill extrusion width"; def->gui_type = "f_enum_open"; def->category = "Extrusion Width"; def->tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for top surfaces. You may want to use thinner extrudates to fill all narrow regions and get a smoother finish. If expressed as percentage (for example 90%) it will be computed over layer height."; @@ -1421,6 +1430,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("top_solid_infill_speed", coFloatOrPercent); def->label = "↳ top solid"; + def->full_label = "Top solid infill speed"; def->gui_type = "f_enum_open"; def->category = "Speed"; def->tooltip = "Speed for printing top solid layers (it only applies to the uppermost external layers and not to their internal solid layers). You may want to slow down this to get a nicer surface finish. This can be expressed as a percentage (for example: 80%) over the solid infill speed above."; From 4c577043f4eefe6a74f6ca2e57d40facd7c1d82e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 18:53:13 +0100 Subject: [PATCH 49/96] Fixed tests broken by the spiral vase change --- lib/Slic3r/GCode/SpiralVase.pm | 2 ++ lib/Slic3r/Print/GCode.pm | 3 +-- t/shells.t | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GCode/SpiralVase.pm b/lib/Slic3r/GCode/SpiralVase.pm index 837e33d16..d35e29e71 100644 --- a/lib/Slic3r/GCode/SpiralVase.pm +++ b/lib/Slic3r/GCode/SpiralVase.pm @@ -9,6 +9,8 @@ use Slic3r::Geometry qw(unscale); sub BUILD { my ($self) = @_; + + $self->reader->Z($self->config->z_offset); $self->reader->apply_print_config($self->config); } diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 635a4b65f..261769716 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -324,8 +324,7 @@ sub process_layer { # check whether we're going to apply spiralvase logic if (defined $self->_spiral_vase) { $self->_spiral_vase->enable( - ($layer->id > 0 || $self->print->config->brim_width == 0 - || $self->print->config->interior_brim_width == 0 || $self->print->config->brim_connections_width == 0) + $layer->id > 0 && ($self->print->config->skirts == 0 || ($layer->id >= $self->print->config->skirt_height && !$self->print->has_infinite_skirt)) && !defined(first { $_->region->config->bottom_solid_layers > $layer->id } @{$layer->regions}) diff --git a/t/shells.t b/t/shells.t index 63eb1905d..2347ff366 100644 --- a/t/shells.t +++ b/t/shells.t @@ -186,7 +186,7 @@ use Slic3r::Test; my $first_layer_temperature_set = 0; my $temperature_set = 0; my @z_steps = (); - Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + Slic3r::GCode::Reader->new(Z => $config->z_offset)->parse(Slic3r::Test::gcode($print), sub { my ($self, $cmd, $args, $info) = @_; if ($cmd eq 'G1') { From 69d169165e024cd76ff38abc4739351d4bc195a3 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 19:17:24 +0100 Subject: [PATCH 50/96] Make sure infill_only_where_needed has no effect when fill_density = 0%. No need to require it to be explicitely turned off for spiral_vase, since it's disabled anyway. #3386 #3126 --- lib/Slic3r/GUI/Tab.pm | 4 +--- lib/Slic3r/Print/Object.pm | 10 ++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index a19bb1e76..770060edf 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -745,14 +745,13 @@ sub _update { my $config = $self->{config}; - if ($config->spiral_vase && !($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0 && $config->infill_only_where_needed == 0 && $config->support_material == 0)) { + if ($config->spiral_vase && !($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0 && $config->support_material == 0)) { my $dialog = Wx::MessageDialog->new($self, "The Spiral Vase mode requires:\n" . "- one perimeter\n" . "- no top solid layers\n" . "- 0% fill density\n" . "- no support material\n" - . "- no infill where necessary\n" . "\nShall I adjust those settings in order to enable Spiral Vase?", 'Spiral Vase', wxICON_WARNING | wxYES | wxNO); if ($dialog->ShowModal() == wxID_YES) { @@ -761,7 +760,6 @@ sub _update { $new_conf->set("top_solid_layers", 0); $new_conf->set("fill_density", 0); $new_conf->set("support_material", 0); - $new_conf->set("infill_only_where_needed", 0); $self->load_config($new_conf); } else { my $new_conf = Slic3r::Config->new; diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index ba6bb62b7..d96c99ed2 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -3,7 +3,7 @@ package Slic3r::Print::Object; use strict; use warnings; -use List::Util qw(min max sum first); +use List::Util qw(min max sum first any); use Slic3r::Flow ':roles'; use Slic3r::Geometry qw(X Y Z PI scale unscale chained_path epsilon); use Slic3r::Geometry::Clipper qw(diff diff_ex intersection intersection_ex union union_ex @@ -488,9 +488,9 @@ sub _support_material { # fill_surfaces but we only turn them into VOID surfaces, thus preserving the boundaries. sub clip_fill_surfaces { my $self = shift; - # sanity check for incompatible options: - # spiral_vase and infill_only_where_needed - return unless $self->config->infill_only_where_needed and not $self->config->spiral_vase; + + return unless $self->config->infill_only_where_needed + && any { $_->config->fill_density > 0 } @{$self->print->regions}; # We only want infill under ceilings; this is almost like an # internal support material. @@ -548,6 +548,8 @@ sub clip_fill_surfaces { # apply new internal infill to regions foreach my $layerm (@{$lower_layer->regions}) { + next if $layerm->config->fill_density == 0; + my (@internal, @other) = (); foreach my $surface (map $_->clone, @{$layerm->fill_surfaces}) { if ($surface->surface_type == S_TYPE_INTERNAL || $surface->surface_type == S_TYPE_INTERNALVOID) { From c4188accc9193b0674486cbc520c0f1e3db22741 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 19:19:34 +0100 Subject: [PATCH 51/96] List ExtUtils::CppGuess as a dependency explicitely. #3329 --- Build.PL | 1 + 1 file changed, 1 insertion(+) diff --git a/Build.PL b/Build.PL index d5f7344cf..ad5147adb 100644 --- a/Build.PL +++ b/Build.PL @@ -10,6 +10,7 @@ my %prereqs = qw( Devel::CheckLib 0 Encode 0 Encode::Locale 1.05 + ExtUtils::CppGuess 0 ExtUtils::MakeMaker 6.80 ExtUtils::ParseXS 3.22 File::Basename 0 From a5b10287d645c171c0577728e5da753949299232 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 20:05:04 +0100 Subject: [PATCH 52/96] Typo --- lib/Slic3r/Print/Object.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index d96c99ed2..11f7b6f29 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -548,7 +548,7 @@ sub clip_fill_surfaces { # apply new internal infill to regions foreach my $layerm (@{$lower_layer->regions}) { - next if $layerm->config->fill_density == 0; + next if $layerm->region->config->fill_density == 0; my (@internal, @other) = (); foreach my $surface (map $_->clone, @{$layerm->fill_surfaces}) { From 4c78e54a4697c96333c71fa00fe39d7696373dcd Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 20:17:59 +0100 Subject: [PATCH 53/96] Compensate for origin_translation when exporting AMF files in order to preserve alignment of further added parts. #3348 --- xs/src/libslic3r/IO/AMF.cpp | 48 +++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/xs/src/libslic3r/IO/AMF.cpp b/xs/src/libslic3r/IO/AMF.cpp index 32471e105..ce49640d0 100644 --- a/xs/src/libslic3r/IO/AMF.cpp +++ b/xs/src/libslic3r/IO/AMF.cpp @@ -528,18 +528,23 @@ AMF::write(Model& model, std::string output_file) std::vector vertices_offsets; int num_vertices = 0; for (ModelVolume *volume : object->volumes) { + volume->mesh.check_topology(); vertices_offsets.push_back(num_vertices); - if (! volume->mesh.repaired) - CONFESS("store_amf() requires repair()"); auto &stl = volume->mesh.stl; if (stl.v_shared == NULL) stl_generate_shared_vertices(&stl); for (size_t i = 0; i < stl.stats.shared_vertices; ++ i) { + // Subtract origin_translation in order to restore the coordinates of the parts + // before they were imported. Otherwise, when this AMF file is reimported parts + // will be placed in the plater correctly, but we will have lost origin_translation + // thus any additional part added will not align with the others. + // In order to do this we compensate for this translation in the instance placement + // below. fprintf(file, " \n"); fprintf(file, " \n"); - fprintf(file, " %f\n", stl.v_shared[i].x); - fprintf(file, " %f\n", stl.v_shared[i].y); - fprintf(file, " %f\n", stl.v_shared[i].z); + fprintf(file, " %f\n", stl.v_shared[i].x - object->origin_translation.x); + fprintf(file, " %f\n", stl.v_shared[i].y - object->origin_translation.y); + fprintf(file, " %f\n", stl.v_shared[i].z - object->origin_translation.z); fprintf(file, " \n"); fprintf(file, " \n"); } @@ -569,24 +574,21 @@ AMF::write(Model& model, std::string output_file) } fprintf(file, " \n"); fprintf(file, " \n"); - if (! object->instances.empty()) { - for (ModelInstance *instance : object->instances) { - char buf[512]; - sprintf(buf, - " \n" - " %lf\n" - " %lf\n" - " %lf\n" - " %lf\n" - " \n", - object_id, - instance->offset.x, - instance->offset.y, - instance->rotation, - instance->scaling_factor); - //FIXME missing instance->scaling_factor - instances.append(buf); - } + for (const ModelInstance* instance : object->instances) { + char buf[512]; + sprintf(buf, + " \n" + " %lf\n" + " %lf\n" + " %lf\n" + " %lf\n" + " \n", + object_id, + instance->offset.x + object->origin_translation.x, + instance->offset.y + object->origin_translation.y, + instance->rotation, + instance->scaling_factor); + instances.append(buf); } } if (! instances.empty()) { From a6609682fc93755ffbee7a7ce7961f1374dfe357 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 20:51:36 +0100 Subject: [PATCH 54/96] Clean IO::AMF::write() --- xs/src/libslic3r/IO/AMF.cpp | 160 ++++++++++++++++-------------- xs/src/libslic3r/TriangleMesh.hpp | 2 +- 2 files changed, 88 insertions(+), 74 deletions(-) diff --git a/xs/src/libslic3r/IO/AMF.cpp b/xs/src/libslic3r/IO/AMF.cpp index ce49640d0..f0bb7a60a 100644 --- a/xs/src/libslic3r/IO/AMF.cpp +++ b/xs/src/libslic3r/IO/AMF.cpp @@ -1,4 +1,6 @@ #include "../IO.hpp" +#include +#include #include #include #include @@ -495,109 +497,121 @@ AMF::read(std::string input_file, Model* model) bool AMF::write(Model& model, std::string output_file) { - FILE *file = ::fopen(output_file.c_str(), "wb"); - if (file == NULL) - return false; - - fprintf(file, "\n"); - fprintf(file, "\n"); - fprintf(file, "Slic3r %s\n", SLIC3R_VERSION); + using namespace std; + + ofstream file; + file.open(output_file, ios::out | ios::trunc); + + file << "" << endl + << "" << endl + << "Slic3r " << SLIC3R_VERSION << "" << endl; + for (const auto &material : model.materials) { if (material.first.empty()) continue; // note that material-id must never be 0 since it's reserved by the AMF spec - fprintf(file, " \n", material.first.c_str()); + file << " " << endl; for (const auto &attr : material.second->attributes) - fprintf(file, " %s\n", attr.first.c_str(), attr.second.c_str()); + file << " " << attr.second << "" << endl; for (const std::string &key : material.second->config.keys()) - fprintf(file, " %s\n", key.c_str(), material.second->config.serialize(key).c_str()); - fprintf(file, " \n"); + file << " " + << material.second->config.serialize(key) << "" << endl; + file << " " << endl; } - std::string instances; - for (size_t object_id = 0; object_id < model.objects.size(); ++ object_id) { + + ostringstream instances; + for (size_t object_id = 0; object_id < model.objects.size(); ++object_id) { ModelObject *object = model.objects[object_id]; - fprintf(file, " \n", object_id); + file << " " << endl; + for (const std::string &key : object->config.keys()) - fprintf(file, " %s\n", key.c_str(), object->config.serialize(key).c_str()); - if (! object->name.empty()) - fprintf(file, " %s\n", object->name.c_str()); + file << " " + << object->config.serialize(key) << "" << endl; + + if (!object->name.empty()) + file << " " << object->name << "" << endl; - //FIXME Store the layer height ranges (ModelObject::layer_height_ranges) - fprintf(file, " \n"); - fprintf(file, " \n"); - std::vector vertices_offsets; - int num_vertices = 0; + //FIXME: Store the layer height ranges (ModelObject::layer_height_ranges) + file << " " << endl; + file << " " << endl; + + std::vector vertices_offsets; + size_t num_vertices = 0; + for (ModelVolume *volume : object->volumes) { - volume->mesh.check_topology(); + volume->mesh.require_shared_vertices(); vertices_offsets.push_back(num_vertices); - auto &stl = volume->mesh.stl; - if (stl.v_shared == NULL) - stl_generate_shared_vertices(&stl); - for (size_t i = 0; i < stl.stats.shared_vertices; ++ i) { + const auto &stl = volume->mesh.stl; + for (size_t i = 0; i < stl.stats.shared_vertices; ++i) // Subtract origin_translation in order to restore the coordinates of the parts // before they were imported. Otherwise, when this AMF file is reimported parts // will be placed in the plater correctly, but we will have lost origin_translation // thus any additional part added will not align with the others. // In order to do this we compensate for this translation in the instance placement // below. - fprintf(file, " \n"); - fprintf(file, " \n"); - fprintf(file, " %f\n", stl.v_shared[i].x - object->origin_translation.x); - fprintf(file, " %f\n", stl.v_shared[i].y - object->origin_translation.y); - fprintf(file, " %f\n", stl.v_shared[i].z - object->origin_translation.z); - fprintf(file, " \n"); - fprintf(file, " \n"); - } + file << " " << endl + << " " << endl + << " " << (stl.v_shared[i].x - object->origin_translation.x) << "" << endl + << " " << (stl.v_shared[i].y - object->origin_translation.y) << "" << endl + << " " << (stl.v_shared[i].z - object->origin_translation.z) << "" << endl + << " " << endl + << " " << endl; + num_vertices += stl.stats.shared_vertices; } - fprintf(file, " \n"); - for (size_t i_volume = 0; i_volume < object->volumes.size(); ++ i_volume) { + file << " " << endl; + + for (size_t i_volume = 0; i_volume < object->volumes.size(); ++i_volume) { ModelVolume *volume = object->volumes[i_volume]; int vertices_offset = vertices_offsets[i_volume]; + if (volume->material_id().empty()) - fprintf(file, " \n"); + file << " " << endl; else - fprintf(file, " \n", volume->material_id().c_str()); + file << " material_id() << "\">" << endl; + for (const std::string &key : volume->config.keys()) - fprintf(file, " %s\n", key.c_str(), volume->config.serialize(key).c_str()); - if (! volume->name.empty()) - fprintf(file, " %s\n", volume->name.c_str()); + file << " " + << volume->config.serialize(key) << "" << endl; + + if (!volume->name.empty()) + file << " " << volume->name << "" << endl; + if (volume->modifier) - fprintf(file, " 1\n"); - for (int i = 0; i < volume->mesh.stl.stats.number_of_facets; ++ i) { - fprintf(file, " \n"); + file << " 1" << endl; + + for (int i = 0; i < volume->mesh.stl.stats.number_of_facets; ++i) { + file << " " << endl; for (int j = 0; j < 3; ++ j) - fprintf(file, " %d\n", j+1, volume->mesh.stl.v_indices[i].vertex[j] + vertices_offset, j+1); - fprintf(file, " \n"); + file << " " + << (volume->mesh.stl.v_indices[i].vertex[j] + vertices_offset) + << "" << endl; + file << " " << endl; } - fprintf(file, " \n"); - } - fprintf(file, " \n"); - fprintf(file, " \n"); - for (const ModelInstance* instance : object->instances) { - char buf[512]; - sprintf(buf, - " \n" - " %lf\n" - " %lf\n" - " %lf\n" - " %lf\n" - " \n", - object_id, - instance->offset.x + object->origin_translation.x, - instance->offset.y + object->origin_translation.y, - instance->rotation, - instance->scaling_factor); - instances.append(buf); + file << " " << endl; } + file << " " << endl; + file << " " << endl; + + for (const ModelInstance* instance : object->instances) + instances + << " " << endl + << " " << instance->offset.x + object->origin_translation.x << "" << endl + << " " << instance->offset.y + object->origin_translation.y << "" << endl + << " %" << instance->rotation << "" << endl + << " " << instance->scaling_factor << "" << endl + << " " << endl; } - if (! instances.empty()) { - fprintf(file, " \n"); - fwrite(instances.data(), instances.size(), 1, file); - fprintf(file, " \n"); - } - fprintf(file, "\n"); - fclose(file); + + std::string instances_str = instances.str(); + if (!instances_str.empty()) + file << " " << endl + << instances_str + << " " << endl; + + file << "" << endl; + + file.close(); return true; } diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index cba8ba43e..51a4e9df4 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -58,6 +58,7 @@ class TriangleMesh bool needed_repair() const; size_t facets_count() const; void extrude_tin(float offset); + void require_shared_vertices(); static TriangleMesh make_cube(double x, double y, double z); static TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/360)); @@ -67,7 +68,6 @@ class TriangleMesh bool repaired; private: - void require_shared_vertices(); friend class TriangleMeshSlicer; friend class TriangleMeshSlicer; friend class TriangleMeshSlicer; From 6b334e29dcf5a6fafab82b5228eba95b5db38dd8 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 17 Mar 2017 14:57:19 -0500 Subject: [PATCH 55/96] change public link for auto builds --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd3c2e29a..57010dd4c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A: Yes. Slic3r [![Build Status](https://travis-ci.org/alexrj/Slic3r.svg?branch=master)](https://travis-ci.org/alexrj/Slic3r) [![Build status](https://ci.appveyor.com/api/projects/status/8iqmeat6cj158vo6?svg=true)](https://ci.appveyor.com/project/lordofhyphens/slic3r) [![Build Status](http://osx-build.slic3r.org:8080/buildStatus/icon?job=Slic3r)](http://osx-build.slic3r.org:8080/job/Slic3r) ====== Prebuilt Windows (64-bit) and OSX (>10.7) builds: -* https://bintray.com/lordofhyphens/Slic3r/slic3r_dev/view (from build server) +* http://dl.slic3r.org/dev/ From d8a8e0d1c1e3867f388f187dcbada51d28d242dc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 21:15:45 +0100 Subject: [PATCH 56/96] Rename/alias --overhangs to --detect-bridging-perimeters to match better the name used in GUI. #3532 --- slic3r.pl | 2 +- xs/src/libslic3r/PrintConfig.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/slic3r.pl b/slic3r.pl index 69bb58593..c881f9560 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -466,7 +466,7 @@ $j --extra-perimeters Add more perimeters when needed (default: yes) --avoid-crossing-perimeters Optimize travel moves so that no perimeters are crossed (default: no) --thin-walls Detect single-width walls (default: yes) - --overhangs Experimental option to use bridge flow, speed and fan for overhangs + --detect-bridging-perimeters Detect bridging perimeters and apply bridge flow, speed and fan (default: yes) Support material options: diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 10efc1b6c..63d600e4e 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -818,7 +818,7 @@ PrintConfigDef::PrintConfigDef() def->label = "Detect bridging perimeters"; def->category = "Layers and Perimeters"; def->tooltip = "Experimental option to adjust flow for overhangs (bridge flow will be used), to apply bridge speed to them and enable fan."; - def->cli = "overhangs!"; + def->cli = "overhangs|detect-bridging-perimeters!"; def->default_value = new ConfigOptionBool(true); def = this->add("perimeter_acceleration", coFloat); From abbc458f106c655c487eec0937e01add02373be5 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 21:47:22 +0100 Subject: [PATCH 57/96] Fix stats output --- lib/Slic3r/Print/Object.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 11f7b6f29..d8e41d77e 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -459,7 +459,7 @@ sub generate_support_material { $self->_support_material->generate($self); $self->set_step_done(STEP_SUPPORTMATERIAL); - my $stats = "Weight: %.1fg, Cost: %.1f" , $self->print->total_weight, $self->print->total_cost; + my $stats = sprintf "Weight: %.1fg, Cost: %.1f" , $self->print->total_weight, $self->print->total_cost; $self->print->status_cb->(85, $stats); } From 4f17a7b236e82554a173f9f93f4539b00ef71426 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 22:38:19 +0100 Subject: [PATCH 58/96] Fixes to CMake compilation --- src/CMakeLists.txt | 8 ++++++-- xs/src/admesh/util.c | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 934f42724..f3d4f4629 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.8) project (slic3r) # only on newer GCCs: -ftemplate-backtrace-limit=0 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DSLIC3R_DEBUG") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) @@ -14,7 +14,8 @@ endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(CMAKE_HOST_APPLE) - set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework CoreFoundation") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE") + set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework CoreFoundation -lc++") ELSE(CMAKE_HOST_APPLE) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") ENDIF(CMAKE_HOST_APPLE) @@ -82,6 +83,7 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/SVG.cpp ${LIBDIR}/libslic3r/TriangleMesh.cpp ) + add_library(admesh STATIC ${LIBDIR}/admesh/connect.c ${LIBDIR}/admesh/normals.c @@ -90,6 +92,8 @@ add_library(admesh STATIC ${LIBDIR}/admesh/stlinit.c ${LIBDIR}/admesh/util.c ) +set_property(TARGET admesh PROPERTY C_STANDARD 99) + add_library(clipper STATIC ${LIBDIR}/clipper.cpp) add_library(expat STATIC ${LIBDIR}/expat/xmlparse.c diff --git a/xs/src/admesh/util.c b/xs/src/admesh/util.c index a786240ad..a2e32c2f5 100644 --- a/xs/src/admesh/util.c +++ b/xs/src/admesh/util.c @@ -192,11 +192,11 @@ void stl_transform(stl_file *stl, float *trafo3x4) { for (i_face = 0; i_face < stl->stats.number_of_facets; ++ i_face) { stl_vertex *vertices = stl->facet_start[i_face].vertex; for (i_vertex = 0; i_vertex < 3; ++ i_vertex) { - stl_vertex &v_dst = vertices[i_vertex]; - stl_vertex v_src = v_dst; - v_dst.x = trafo3x4[0] * v_src.x + trafo3x4[1] * v_src.y + trafo3x4[2] * v_src.z + trafo3x4[3]; - v_dst.y = trafo3x4[4] * v_src.x + trafo3x4[5] * v_src.y + trafo3x4[6] * v_src.z + trafo3x4[7]; - v_dst.z = trafo3x4[8] * v_src.x + trafo3x4[9] * v_src.y + trafo3x4[10] * v_src.z + trafo3x4[11]; + stl_vertex* v_dst = &vertices[i_vertex]; + stl_vertex v_src = *v_dst; + v_dst->x = trafo3x4[0] * v_src.x + trafo3x4[1] * v_src.y + trafo3x4[2] * v_src.z + trafo3x4[3]; + v_dst->y = trafo3x4[4] * v_src.x + trafo3x4[5] * v_src.y + trafo3x4[6] * v_src.z + trafo3x4[7]; + v_dst->z = trafo3x4[8] * v_src.x + trafo3x4[9] * v_src.y + trafo3x4[10] * v_src.z + trafo3x4[11]; } } stl_get_size(stl); From c9f0a4c934f5cb3406f752b2a521817150d979e8 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Mar 2017 22:51:07 +0100 Subject: [PATCH 59/96] Quick fix for Quick Slice. #3773 --- lib/Slic3r/GUI/MainFrame.pm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index a3c04cd25..ddf67a28f 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -415,11 +415,7 @@ sub quick_slice { $sprint->apply_config($config); $sprint->set_model($model); - - { - my $extra = $self->extra_variables; - $sprint->placeholder_parser->set($_, $extra->{$_}) for keys %$extra; - } + # FIXME: populate placeholders (preset names etc.) # select output file my $output_file; From 90395f93940410093244e9cfcaf3dce407ddc811 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 00:48:24 +0100 Subject: [PATCH 60/96] Complete implementation of read_cli() --- xs/src/libslic3r/Config.cpp | 128 +++++++++++++++++++++++++----------- xs/src/libslic3r/Config.hpp | 32 +++++---- xs/t/15_config.t | 43 +++++++++++- xs/xsp/Config.xsp | 2 + 4 files changed, 154 insertions(+), 51 deletions(-) diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index ccb357cf2..66b3d0445 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -106,7 +106,6 @@ bool unescape_string_cstyle(const std::string &str, std::string &str_out) bool unescape_strings_cstyle(const std::string &str, std::vector &out) { - out.clear(); if (str.empty()) return true; @@ -500,56 +499,109 @@ DynamicConfig::erase(const t_config_option_key &opt_key) { this->options.erase(opt_key); } +void +DynamicConfig::read_cli(const std::vector &tokens, t_config_option_keys* extra) +{ + std::vector _argv; + + // push a bogus executable name (argv[0]) + _argv.push_back(""); + + for (size_t i = 0; i < tokens.size(); ++i) + _argv.push_back(const_cast(tokens[i].c_str())); + + this->read_cli(_argv.size(), &_argv[0], extra); +} + void DynamicConfig::read_cli(const int argc, const char** argv, t_config_option_keys* extra) { + // cache the CLI option => opt_key mapping + std::map opts; + for (const auto &oit : this->def->options) { + std::string cli = oit.second.cli; + cli = cli.substr(0, cli.find("=")); + boost::trim_right_if(cli, boost::is_any_of("!")); + std::vector tokens; + boost::split(tokens, cli, boost::is_any_of("|")); + for (const std::string &t : tokens) + opts[t] = oit.first; + } + bool parse_options = true; for (int i = 1; i < argc; ++i) { std::string token = argv[i]; + // Store non-option arguments in the provided vector. + if (!parse_options || !boost::starts_with(token, "-")) { + extra->push_back(token); + continue; + } + + + // Stop parsing tokens as options when -- is supplied. if (token == "--") { - // stop parsing tokens as options parse_options = false; - } else if (parse_options && boost::starts_with(token, "-")) { - boost::algorithm::trim_left_if(token, boost::algorithm::is_any_of("-")); - // TODO: handle --key=value - - // look for the option def - t_config_option_key opt_key; - const ConfigOptionDef* optdef; - for (t_optiondef_map::const_iterator oit = this->def->options.begin(); - oit != this->def->options.end(); ++oit) { - optdef = &oit->second; - - if (optdef->cli == token - || optdef->cli == token + '!' - || boost::starts_with(optdef->cli, token + "=") - || boost::starts_with(optdef->cli, token + "|") - || (token.length() == 1 && boost::contains(optdef->cli, "|" + token))) { - opt_key = oit->first; - break; - } + continue; + } + + // Remove leading dashes + boost::trim_left_if(token, boost::is_any_of("-")); + + // Remove the "no-" prefix used to negate boolean options. + bool no = false; + if (boost::starts_with(token, "no-")) { + no = true; + boost::replace_first(token, "no-", ""); + } + + // Read value when supplied in the --key=value form. + std::string value; + { + size_t equals_pos = token.find("="); + if (equals_pos != std::string::npos) { + value = token.substr(equals_pos+1); + token.erase(equals_pos); } - - if (opt_key.empty()) { - printf("Warning: unknown option --%s\n", token.c_str()); + } + + // Look for the cli -> option mapping. + const auto it = opts.find(token); + if (it == opts.end()) { + printf("Warning: unknown option --%s\n", token.c_str()); + continue; + } + const t_config_option_key opt_key = it->second; + const ConfigOptionDef &optdef = this->def->options.at(opt_key); + + // If the option type expects a value and it was not already provided, + // look for it in the next token. + if (optdef.type != coBool && optdef.type != coBools && value.empty()) { + if (i == (argc-1)) { + printf("No value supplied for --%s\n", token.c_str()); continue; } - - if (ConfigOptionBool* opt = this->opt(opt_key, true)) { - opt->value = !boost::starts_with(token, "no-"); - } else if (ConfigOptionBools* opt = this->opt(opt_key, true)) { - opt->values.push_back(!boost::starts_with(token, "no-")); - } else { - // we expect one more token carrying the value - if (i == (argc-1)) { - printf("No value supplied for --%s\n", token.c_str()); - exit(1); - } - this->set_deserialize(opt_key, argv[++i], true); - } + value = argv[++i]; + } + + // Store the option value. + const bool existing = this->has(opt_key); + if (ConfigOptionBool* opt = this->opt(opt_key, true)) { + opt->value = !no; + } else if (ConfigOptionBools* opt = this->opt(opt_key, true)) { + if (!existing) opt->values.clear(); // remove the default values + opt->values.push_back(!no); + } else if (ConfigOptionStrings* opt = this->opt(opt_key, true)) { + if (!existing) opt->values.clear(); // remove the default values + opt->deserialize(value, true); + } else if (ConfigOptionFloats* opt = this->opt(opt_key, true)) { + if (!existing) opt->values.clear(); // remove the default values + opt->deserialize(value, true); + } else if (ConfigOptionPoints* opt = this->opt(opt_key, true)) { + if (!existing) opt->values.clear(); // remove the default values + opt->deserialize(value, true); } else { - extra->push_back(token); + this->set_deserialize(opt_key, value, true); } } } diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 8e375701e..32a80adee 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -12,6 +12,9 @@ #include #include "libslic3r.h" #include "Point.hpp" +#include +#include +#include namespace Slic3r { @@ -248,6 +251,7 @@ class ConfigOptionStrings : public ConfigOptionVector }; bool deserialize(std::string str, bool append = false) { + if (!append) this->values.clear(); return unescape_strings_cstyle(str, this->values); }; }; @@ -392,20 +396,23 @@ class ConfigOptionPoints : public ConfigOptionVector bool deserialize(std::string str, bool append = false) { if (!append) this->values.clear(); - std::istringstream is(str); - std::string point_str; - while (std::getline(is, point_str, ',')) { - Pointf point; - std::istringstream iss(point_str); - std::string coord_str; - if (std::getline(iss, coord_str, 'x')) { - std::istringstream(coord_str) >> point.x; - if (std::getline(iss, coord_str, 'x')) { - std::istringstream(coord_str) >> point.y; - } + + std::vector tokens; + boost::split(tokens, str, boost::is_any_of("x,")); + if (tokens.size() % 2) return false; + + try { + for (size_t i = 0; i < tokens.size(); ++i) { + Pointf point; + point.x = boost::lexical_cast(tokens[i]); + point.y = boost::lexical_cast(tokens[++i]); + this->values.push_back(point); } - this->values.push_back(point); + } catch (boost::bad_lexical_cast &e) { + printf("%s\n", e.what()); + return false; } + return true; }; }; @@ -691,6 +698,7 @@ class DynamicConfig : public virtual ConfigBase virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false); t_config_option_keys keys() const; void erase(const t_config_option_key &opt_key); + void read_cli(const std::vector &tokens, t_config_option_keys* extra); void read_cli(const int argc, const char **argv, t_config_option_keys* extra); private: diff --git a/xs/t/15_config.t b/xs/t/15_config.t index 256fa539f..214baad9f 100644 --- a/xs/t/15_config.t +++ b/xs/t/15_config.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 147; +use Test::More tests => 159; use Data::Dumper; foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintConfig) { @@ -251,4 +251,45 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintCo ok 1, 'did not crash on reading invalid items in config'; } +{ + my $parse = sub { + my @argv = @_; + my $config = Slic3r::Config->new; + $config->read_cli(\@argv); + return $config; + }; + { + my $config = $parse->(qw(--extra-perimeters --perimeters 1 --layer-height 0.45 + --fill-density 70% --detect-bridging-perimeters --notes=foobar)); + is $config->get('extra_perimeters'), 1, 'read_cli(): bool'; + is $config->get('perimeters'), 1, 'read_cli(): int'; + is $config->get('layer_height'), 0.45, 'read_cli(): float'; + is $config->serialize('fill_density'), '70%', 'read_cli(): percent'; + is $config->get('overhangs'), 1, 'read_cli(): alternative'; + is $config->get('notes'), 'foobar', 'read_cli(): key=val'; + } + { + my $config = $parse->(qw(--extra-perimeters --no-extra-perimeters)); + ok $config->has('extra_perimeters'), 'read_cli(): negated bool'; + is_deeply $config->get('extra_perimeters'), 0, 'read_cli(): negated bool'; + } + { + my $config = $parse->(qw(--wipe --no-wipe --wipe)); + is_deeply $config->get('wipe'), [1,0,1], 'read_cli(): bools array'; + } + { + my $config = $parse->(qw(--post-process foo --post-process bar)); + is_deeply $config->get('post_process'), ['foo', 'bar'], 'read_cli(): strings array'; + } + { + my $config = $parse->(qw(--retract-speed 0.4 --retract-speed 0.5)); + is_deeply $config->get('retract_speed'), [0.4, 0.5], 'read_cli(): floats array'; + } + { + my $config = $parse->(qw(--extruder-offset 0,0 --extruder-offset 10x5)); + is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], + [[0,0], [10,5]], 'read_cli(): points array'; + } +} + __END__ diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index 96c4830e0..6b4fb1950 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -40,6 +40,8 @@ double min_object_distance(); %name{_load} void load(std::string file); %name{_save} void save(std::string file); + std::vector read_cli(std::vector _argv) + %code{% THIS->read_cli(_argv, &RETVAL); %}; }; %name{Slic3r::Config::Static} class StaticPrintConfig { From e7c854c91917c3ed9ecc923a5bc442fcd7f00ce9 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 11:29:48 +0100 Subject: [PATCH 61/96] Ported Config::_handle_legacy() to XS --- lib/Slic3r/Config.pm | 66 +--------------------------- xs/src/libslic3r/Config.cpp | 34 ++++++++++++--- xs/src/libslic3r/Config.hpp | 3 +- xs/src/libslic3r/PrintConfig.cpp | 74 ++++++++++++++++++++++++++++++++ xs/src/libslic3r/PrintConfig.hpp | 5 ++- 5 files changed, 110 insertions(+), 72 deletions(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 5168ddf94..2763a8fd0 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -8,12 +8,6 @@ use utf8; use List::Util qw(first max); -# cemetery of old config settings -our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration - adjust_overhang_flow standby_temperature scale rotate duplicate duplicate_grid - rotate scale duplicate_grid start_perimeters_at_concave_points start_perimeters_at_non_overhang - randomize_start seal_position bed_size print_center g0); - # C++ Slic3r::PrintConfigDef exported as a Perl hash of hashes. # The C++ counterpart is a constant singleton. our $Options = print_config_def(); @@ -120,11 +114,7 @@ sub load_ini_hash { my ($ini_hash) = @_; my $config = $class->new; - foreach my $opt_key (keys %$ini_hash) { - ($opt_key, my $value) = _handle_legacy($opt_key, $ini_hash->{$opt_key}); - next if !defined $opt_key; - $config->set_deserialize($opt_key, $value); - } + $config->set_deserialize($_, $ini_hash->{$_}) for keys %$ini_hash; return $config; } @@ -145,60 +135,6 @@ sub get_value { : $self->get($opt_key); } -sub _handle_legacy { - my ($opt_key, $value) = @_; - - # handle legacy options - if ($opt_key =~ /^(extrusion_width|bottom_layer_speed|first_layer_height)_ratio$/) { - $opt_key = $1; - $opt_key =~ s/^bottom_layer_speed$/first_layer_speed/; - $value = $value =~ /^\d+(?:\.\d+)?$/ && $value != 0 ? ($value*100) . "%" : 0; - } - if ($opt_key eq 'threads' && !$Slic3r::have_threads) { - $value = 1; - } - if ($opt_key eq 'gcode_flavor' && $value eq 'makerbot') { - $value = 'makerware'; - } - if ($opt_key eq 'fill_density' && defined($value) && $value !~ /%/ && $value <= 1) { - # fill_density was turned into a percent value - $value *= 100; - $value = "$value"; # force update of the PV value, workaround for bug https://rt.cpan.org/Ticket/Display.html?id=94110 - } - if ($opt_key eq 'randomize_start' && $value) { - $opt_key = 'seam_position'; - $value = 'random'; - } - if ($opt_key eq 'bed_size' && $value) { - $opt_key = 'bed_shape'; - my ($x, $y) = split /,/, $value; - $value = "0x0,${x}x0,${x}x${y},0x${y}"; - } - return () if first { $_ eq $opt_key } @Ignore; - - # For historical reasons, the world's full of configs having these very low values; - # to avoid unexpected behavior we need to ignore them. Banning these two hard-coded - # values is a dirty hack and will need to be removed sometime in the future, but it - # will avoid lots of complaints for now. - if ($opt_key eq 'perimeter_acceleration' && $value == '25') { - $value = 0; - } - if ($opt_key eq 'infill_acceleration' && $value == '50') { - $value = 0; - } - - if (!exists $Options->{$opt_key}) { - my @keys = grep { $Options->{$_}{aliases} && grep $_ eq $opt_key, @{$Options->{$_}{aliases}} } keys %$Options; - if (!@keys) { - warn "Unknown option $opt_key\n"; - return (); - } - $opt_key = $keys[0]; - } - - return ($opt_key, $value); -} - # Create a hash of hashes from the underlying C++ Slic3r::DynamicPrintConfig. # The first hash key is '_' meaning no category. sub as_ini { diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 66b3d0445..9901282ff 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -220,6 +221,12 @@ ConfigDef::add(const t_config_option_key &opt_key, const ConfigOptionDef &def) return &this->options[opt_key]; } +bool +ConfigDef::has(const t_config_option_key &opt_key) const +{ + return this->options.count(opt_key) > 0; +} + const ConfigOptionDef* ConfigDef::get(const t_config_option_key &opt_key) const { @@ -288,12 +295,27 @@ ConfigBase::serialize(const t_config_option_key &opt_key) const { } bool -ConfigBase::set_deserialize(const t_config_option_key &opt_key, std::string str, bool append) { +ConfigBase::set_deserialize(t_config_option_key opt_key, std::string str, bool append) { const ConfigOptionDef* optdef = this->def->get(opt_key); - if (optdef == NULL) throw UnknownOptionException(); + if (optdef == NULL) { + // If we didn't find an option, look for any other option having this as an alias. + for (const auto &opt : this->def->options) { + for (const t_config_option_key &opt_key2 : opt.second.aliases) { + if (opt_key2 == opt_key) { + opt_key = opt_key2; + optdef = &opt.second; + break; + } + } + if (optdef != NULL) break; + } + if (optdef == NULL) + throw UnknownOptionException(); + } + if (!optdef->shortcut.empty()) { - for (std::vector::const_iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { - if (!this->set_deserialize(*it, str)) return false; + for (const t_config_option_key &shortcut : optdef->shortcut) { + if (!this->set_deserialize(shortcut, str)) return false; } return true; } @@ -373,7 +395,9 @@ ConfigBase::load(const std::string &file) pt::read_ini(file, tree); BOOST_FOREACH(const pt::ptree::value_type &v, tree) { try { - this->set_deserialize(v.first.c_str(), v.second.get_value().c_str()); + t_config_option_key opt_key = v.first; + std::string value = v.second.get_value(); + this->set_deserialize(opt_key, value); } catch (UnknownOptionException &e) { // ignore } diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 32a80adee..412c65fd3 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -649,6 +649,7 @@ class ConfigDef t_optiondef_map options; ConfigOptionDef* add(const t_config_option_key &opt_key, ConfigOptionType type); ConfigOptionDef* add(const t_config_option_key &opt_key, const ConfigOptionDef &def); + bool has(const t_config_option_key &opt_key) const; const ConfigOptionDef* get(const t_config_option_key &opt_key) const; void merge(const ConfigDef &other); }; @@ -675,7 +676,7 @@ class ConfigBase bool equals(ConfigBase &other); t_config_option_keys diff(ConfigBase &other); std::string serialize(const t_config_option_key &opt_key) const; - bool set_deserialize(const t_config_option_key &opt_key, std::string str, bool append = false); + virtual bool set_deserialize(t_config_option_key opt_key, std::string str, bool append = false); double get_abs_value(const t_config_option_key &opt_key) const; double get_abs_value(const t_config_option_key &opt_key, double ratio_over) const; void setenv_(); diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 63d600e4e..5a932bde7 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1,4 +1,5 @@ #include "PrintConfig.hpp" +#include #include namespace Slic3r { @@ -1577,6 +1578,79 @@ PrintConfigBase::min_object_distance() const : duplicate_distance; } +bool +PrintConfigBase::set_deserialize(t_config_option_key opt_key, std::string str, bool append) +{ + this->_handle_legacy(opt_key, str); + if (opt_key.empty()) return true; // ignore option + return ConfigBase::set_deserialize(opt_key, str, append); +} + +void +PrintConfigBase::_handle_legacy(t_config_option_key &opt_key, std::string &value) const +{ + // handle legacy options + if (opt_key == "extrusion_width_ratio" || opt_key == "bottom_layer_speed_ratio" + || opt_key == "first_layer_height_ratio") { + boost::replace_first(opt_key, "_ratio", ""); + if (opt_key == "bottom_layer_speed") opt_key = "first_layer_speed"; + try { + float v = boost::lexical_cast(value); + if (v != 0) + value = boost::lexical_cast(v*100) + "%"; + } catch (boost::bad_lexical_cast &) { + value = "0"; + } + } else if (opt_key == "gcode_flavor" && value == "makerbot") { + value = "makerware"; + } else if (opt_key == "fill_density" && value.find("%") == std::string::npos) { + try { + // fill_density was turned into a percent value + float v = boost::lexical_cast(value); + value = boost::lexical_cast(v*100) + "%"; + } catch (boost::bad_lexical_cast &) {} + } else if (opt_key == "randomize_start" && value == "1") { + opt_key = "seam_position"; + value = "random"; + } else if (opt_key == "bed_size" && !value.empty()) { + opt_key = "bed_shape"; + ConfigOptionPoint p; + p.deserialize(value); + std::ostringstream oss; + oss << "0x0," << p.value.x << "x0," << p.value.x << "x" << p.value.y << ",0x" << p.value.y; + value = oss.str(); + } else if ((opt_key == "perimeter_acceleration" && value == "25") + || (opt_key == "infill_acceleration" && value == "50")) { + /* For historical reasons, the world's full of configs having these very low values; + to avoid unexpected behavior we need to ignore them. Banning these two hard-coded + values is a dirty hack and will need to be removed sometime in the future, but it + will avoid lots of complaints for now. */ + value = "0"; + } + + // cemetery of old config settings + if (opt_key == "duplicate_x" || opt_key == "duplicate_y" || opt_key == "multiply_x" + || opt_key == "multiply_y" || opt_key == "support_material_tool" + || opt_key == "acceleration" || opt_key == "adjust_overhang_flow" + || opt_key == "standby_temperature" || opt_key == "scale" || opt_key == "rotate" + || opt_key == "duplicate" || opt_key == "duplicate_grid" || opt_key == "rotate" + || opt_key == "scale" || opt_key == "duplicate_grid" + || opt_key == "start_perimeters_at_concave_points" + || opt_key == "start_perimeters_at_non_overhang" || opt_key == "randomize_start" + || opt_key == "seal_position" || opt_key == "bed_size" + || opt_key == "print_center" || opt_key == "g0" || opt_key == "threads") + { + opt_key = ""; + return; + } + + if (!this->def->has(opt_key)) { + printf("Unknown option %s\n", opt_key.c_str()); + opt_key = ""; + return; + } +} + CLIConfigDef::CLIConfigDef() { ConfigOptionDef* def; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 2ea423d8c..5cf7054bf 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -112,8 +112,11 @@ class PrintConfigBase : public virtual ConfigBase PrintConfigBase() { this->def = &print_config_def; }; - + bool set_deserialize(t_config_option_key opt_key, std::string str, bool append = false); double min_object_distance() const; + + protected: + void _handle_legacy(t_config_option_key &opt_key, std::string &value) const; }; // Slic3r dynamic configuration, used to override the configuration From 7467eb8fbb869404f27c0295c131ee393658c628 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 12:28:53 +0100 Subject: [PATCH 62/96] Merge all OctoPrint print options in a single dialog (bypassable by pressing the Alt key). #3765 #3655 --- lib/Slic3r/GUI/Plater.pm | 127 ++++++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 23 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index c62067371..03477b811 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -14,7 +14,7 @@ use Wx qw(:button :cursor :dialog :filedialog :keycode :icon :font :id :listctrl :panel :sizer :toolbar :window wxTheApp :notebook :combobox); use Wx::Event qw(EVT_BUTTON EVT_COMMAND EVT_KEY_DOWN EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL - EVT_CHOICE EVT_COMBOBOX EVT_TIMER EVT_NOTEBOOK_PAGE_CHANGED); + EVT_CHOICE EVT_COMBOBOX EVT_TIMER EVT_NOTEBOOK_PAGE_CHANGED EVT_LEFT_UP); use base 'Wx::Panel'; use constant TB_ADD => &Wx::NewId; @@ -253,34 +253,46 @@ sub new { EVT_BUTTON($self, $self->{btn_print}, sub { $self->{print_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir()); }); - EVT_BUTTON($self, $self->{btn_send_gcode}, sub { + EVT_LEFT_UP($self->{btn_send_gcode}, sub { + my (undef, $e) = @_; + my $filename = basename($self->{print}->output_filepath($main::opt{output} // '')); - $filename = Wx::GetTextFromUser("Save to printer with the following name:", - "OctoPrint", $filename, $self); - my $process_dialog = Wx::ProgressDialog->new('Querying OctoPrint…', "Checking whether file already exists…", 100, $self, 0); - $process_dialog->Pulse; + if (!$e->AltDown) { + # When the alt key is pressed, bypass the dialog. + my $dlg = Slic3r::GUI::Plater::OctoPrintSpoolDialog->new($self, $filename); + return unless $dlg->ShowModal == wxID_OK; + $filename = $dlg->{filename}; + } - my $ua = LWP::UserAgent->new; - $ua->timeout(5); - my $res = $ua->get("http://" . $self->{config}->octoprint_host . "/api/files/local"); - $process_dialog->Destroy; - if ($res->is_success) { - if ($res->decoded_content =~ /"name":\s*"\Q$filename\E"/) { - my $dialog = Wx::MessageDialog->new($self, - "It looks like a file with the same name already exists in the server. " - . "Shall I overwrite it?", - 'OctoPrint', wxICON_WARNING | wxYES | wxNO); - return if $dialog->ShowModal() == wxID_NO; + if (!$Slic3r::GUI::Settings->{octoprint}{overwrite}) { + my $progress = Wx::ProgressDialog->new('Querying OctoPrint…', + "Checking whether file already exists…", 100, $self, 0); + $progress->Pulse; + + my $ua = LWP::UserAgent->new; + $ua->timeout(5); + my $res = $ua->get("http://" . $self->{config}->octoprint_host . "/api/files/local"); + $progress->Destroy; + if ($res->is_success) { + if ($res->decoded_content =~ /"name":\s*"\Q$filename\E"/) { + my $dialog = Wx::MessageDialog->new($self, + "It looks like a file with the same name already exists in the server. " + . "Shall I overwrite it?", + 'OctoPrint', wxICON_WARNING | wxYES | wxNO); + if ($dialog->ShowModal() == wxID_NO) { + return; + } + } + } else { + my $message = "Error while connecting to the OctoPrint server: " . $res->status_line; + Slic3r::GUI::show_error($self, $message); + return; } } - my $dialog = Wx::MessageDialog->new($self, - "Shall I start the print after uploading the file?", - 'OctoPrint', wxICON_QUESTION | wxYES | wxNO); - $self->{send_gcode_file_print} = ($dialog->ShowModal() == wxID_YES); - - $self->{send_gcode_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir() . "/$filename"); + $self->{send_gcode_file_print} = $Slic3r::GUI::Settings->{octoprint}{start}; + $self->{send_gcode_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir() . "/" . $filename); }); EVT_BUTTON($self, $self->{btn_export_stl}, \&export_stl); @@ -2117,4 +2129,73 @@ sub transform_thumbnail { $self->transformed_thumbnail($t); } +package Slic3r::GUI::Plater::OctoPrintSpoolDialog; +use Wx qw(:dialog :id :misc :sizer :icon wxTheApp); +use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER); +use base 'Wx::Dialog'; + +sub new { + my $class = shift; + my ($parent, $filename) = @_; + my $self = $class->SUPER::new($parent, -1, "Send to OctoPrint", wxDefaultPosition, + [400, -1]); + + $self->{filename} = $filename; + $Slic3r::GUI::Settings->{octoprint} //= {}; + + my $optgroup; + $optgroup = Slic3r::GUI::OptionsGroup->new( + parent => $self, + title => 'Send to OctoPrint', + on_change => sub { + my ($opt_id) = @_; + + if ($opt_id eq 'filename') { + $self->{filename} = $optgroup->get_value($opt_id); + } else { + $Slic3r::GUI::Settings->{octoprint}{$opt_id} = $optgroup->get_value($opt_id); + } + }, + label_width => 200, + ); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'filename', + type => 's', + label => 'File name', + width => 200, + tooltip => 'The name used for labelling the print job.', + default => $filename, + )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'overwrite', + type => 'bool', + label => 'Overwrite existing file', + tooltip => 'If selected, any existing file with the same name will be overwritten without confirmation.', + default => $Slic3r::GUI::Settings->{octoprint}{overwrite} // 0, + )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'start', + type => 'bool', + label => 'Start print', + tooltip => 'If selected, print will start after the upload.', + default => $Slic3r::GUI::Settings->{octoprint}{start} // 0, + )); + + my $sizer = Wx::BoxSizer->new(wxVERTICAL); + $sizer->Add($optgroup->sizer, 0, wxEXPAND | wxTOP | wxBOTTOM | wxLEFT | wxRIGHT, 10); + + my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + $sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + EVT_BUTTON($self, wxID_OK, sub { + wxTheApp->save_settings; + $self->EndModal(wxID_OK); + $self->Close; # needed on Linux + }); + + $self->SetSizer($sizer); + $sizer->SetSizeHints($self); + + return $self; +} + 1; From 702cf43a0a9a86c2db9dfb27d50aa631cffe6b19 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 14:56:23 +0100 Subject: [PATCH 63/96] Bugfix: prevent crashes from rounding issues caused by almost-collinear points in the new FillRectilinear. #3684 --- xs/src/libslic3r/ExPolygon.cpp | 8 +++++++ xs/src/libslic3r/ExPolygon.hpp | 1 + xs/src/libslic3r/Fill/FillRectilinear.cpp | 15 ++++++++----- xs/src/libslic3r/Polygon.cpp | 26 +++++++++++++++++++++++ xs/src/libslic3r/Polygon.hpp | 2 ++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index 19c3184f3..ec02acc35 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -129,6 +129,14 @@ ExPolygon::has_boundary_point(const Point &point) const return false; } +void +ExPolygon::remove_vertical_collinear_points(coord_t tolerance) +{ + this->contour.remove_vertical_collinear_points(tolerance); + for (Polygon &p : this->holes) + p.remove_vertical_collinear_points(tolerance); +} + void ExPolygon::simplify_p(double tolerance, Polygons* polygons) const { diff --git a/xs/src/libslic3r/ExPolygon.hpp b/xs/src/libslic3r/ExPolygon.hpp index 4289eb390..63cc560cd 100644 --- a/xs/src/libslic3r/ExPolygon.hpp +++ b/xs/src/libslic3r/ExPolygon.hpp @@ -29,6 +29,7 @@ class ExPolygon bool contains(const Point &point) const; bool contains_b(const Point &point) const; bool has_boundary_point(const Point &point) const; + void remove_vertical_collinear_points(coord_t tolerance); void simplify_p(double tolerance, Polygons* polygons) const; Polygons simplify_p(double tolerance) const; ExPolygons simplify(double tolerance) const; diff --git a/xs/src/libslic3r/Fill/FillRectilinear.cpp b/xs/src/libslic3r/Fill/FillRectilinear.cpp index cc7b0ca13..2d3c84eb0 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.cpp @@ -1,3 +1,9 @@ +//#define DEBUG_RECTILINEAR +#ifdef DEBUG_RECTILINEAR + #undef NDEBUG + #include "../SVG.hpp" +#endif + #include "../ClipperUtils.hpp" #include "../ExPolygon.hpp" #include "../PolylineCollection.hpp" @@ -7,17 +13,16 @@ #include "FillRectilinear.hpp" -//#define DEBUG_RECTILINEAR -#ifdef DEBUG_RECTILINEAR - #include "../SVG.hpp" -#endif - namespace Slic3r { void FillRectilinear::_fill_single_direction(ExPolygon expolygon, const direction_t &direction, coord_t x_shift, Polylines* out) { + // Remove almost collinear points (vertical ones might break this algorithm + // because of rounding). + expolygon.remove_vertical_collinear_points(1); + // rotate polygons so that we can work with vertical lines here expolygon.rotate(-direction.first); diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index e36512970..3d87a986b 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -148,6 +148,32 @@ Polygon::contains(const Point &point) const return result; } +void +Polygon::douglas_peucker(double tolerance) +{ + this->points.push_back(this->points.front()); + this->points = MultiPoint::_douglas_peucker(this->points, tolerance); + this->points.pop_back(); +} + +void +Polygon::remove_vertical_collinear_points(coord_t tolerance) +{ + Points &pp = this->points; + pp.push_back(pp.front()); + for (size_t i = 0; i < pp.size()-1; ++i) { + while (i < pp.size()-1) { + Point &next = pp[i+1]; + if (std::abs(next.x - pp[i].x) <= tolerance) { + pp.erase(pp.begin() + i+1); + } else { + break; + } + } + } + pp.pop_back(); +} + // this only works on CCW polygons as CW will be ripped out by Clipper's simplify_polygons() Polygons Polygon::simplify(double tolerance) const diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index 1b9887218..b1576ad27 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -39,6 +39,8 @@ class Polygon : public MultiPoint { // Does an unoriented polygon contain a point? // Tested by counting intersections along a horizontal line. bool contains(const Point &point) const; + void douglas_peucker(double tolerance); + void remove_vertical_collinear_points(coord_t tolerance); Polygons simplify(double tolerance) const; void simplify(double tolerance, Polygons &polygons) const; void triangulate_convex(Polygons* polygons) const; From 7eed7f2dba5851b2c8cd7f5650151e107acde6ff Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 15:37:16 +0100 Subject: [PATCH 64/96] Fixed previous commit --- xs/src/libslic3r/Polygon.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index 3d87a986b..5d12b3062 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -163,9 +163,10 @@ Polygon::remove_vertical_collinear_points(coord_t tolerance) pp.push_back(pp.front()); for (size_t i = 0; i < pp.size()-1; ++i) { while (i < pp.size()-1) { - Point &next = pp[i+1]; - if (std::abs(next.x - pp[i].x) <= tolerance) { - pp.erase(pp.begin() + i+1); + const Point &p = pp[i]; + const Point &next = pp[i+1]; + if (next.x == p.x && std::abs(next.y - p.y) <= tolerance) { + pp.erase(pp.begin() + i); } else { break; } From b571f4af8475ecbb599bc9323f23164f8482bf20 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 15:59:21 +0100 Subject: [PATCH 65/96] Bugfix: scale to size didn't work multiple times. #3768 --- lib/Slic3r/GUI/Plater.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 03477b811..74078f76d 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1008,7 +1008,7 @@ sub changescale { my $newsize = Wx::GetTextFromUser("Enter the new max size for the selected object:", "Scale", $cursize, $self); return if !$newsize || $newsize !~ /^\d*(?:\.\d*)?$/ || $newsize < 0; - $scale = $newsize / $cursize * 100; + $scale = $model_instance->scaling_factor * $newsize / $cursize * 100; } else { # max scale factor should be above 2540 to allow importing files exported in inches # Wx::GetNumberFromUser() does not support decimal numbers From c773d407fdb420109dc0e4e04ef90d9e5eb82675 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 16:11:31 +0100 Subject: [PATCH 66/96] Allow spiral_vase with multiple copies/objects when Sequential Printing is enabled --- xs/src/libslic3r/Print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index f7c722265..a3007801d 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -660,7 +660,7 @@ Print::validate() const if (this->config.spiral_vase) { size_t total_copies_count = 0; FOREACH_OBJECT(this, i_object) total_copies_count += (*i_object)->copies().size(); - if (total_copies_count > 1) + if (total_copies_count > 1 && !this->config.complete_objects) return "The Spiral Vase option can only be used when printing a single object."; if (this->regions.size() > 1) return "The Spiral Vase option can only be used when printing single material objects."; From 35be0eefef1a73cc2a909afa4fe9d30256c7b9e2 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 18 Mar 2017 11:44:06 -0500 Subject: [PATCH 67/96] Remove boost references from Config.hpp (this does not work on Windows!) --- xs/src/libslic3r/Config.cpp | 24 ++++++++++++++++++++++++ xs/src/libslic3r/Config.hpp | 25 +------------------------ xs/src/libslic3r/PrintConfig.cpp | 1 + 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 9901282ff..2937f7d64 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -682,4 +683,27 @@ ConfigOptionPoint3::deserialize(std::string str, bool append) { return true; }; +bool +ConfigOptionPoints::deserialize(std::string str, bool append) { + if (!append) this->values.clear(); + + std::vector tokens; + boost::split(tokens, str, boost::is_any_of("x,")); + if (tokens.size() % 2) return false; + + try { + for (size_t i = 0; i < tokens.size(); ++i) { + Pointf point; + point.x = boost::lexical_cast(tokens[i]); + point.y = boost::lexical_cast(tokens[++i]); + this->values.push_back(point); + } + } catch (boost::bad_lexical_cast &e) { + printf("%s\n", e.what()); + return false; + } + + return true; +} + } diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 412c65fd3..127efa06d 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -12,9 +12,6 @@ #include #include "libslic3r.h" #include "Point.hpp" -#include -#include -#include namespace Slic3r { @@ -394,27 +391,7 @@ class ConfigOptionPoints : public ConfigOptionVector return vv; }; - bool deserialize(std::string str, bool append = false) { - if (!append) this->values.clear(); - - std::vector tokens; - boost::split(tokens, str, boost::is_any_of("x,")); - if (tokens.size() % 2) return false; - - try { - for (size_t i = 0; i < tokens.size(); ++i) { - Pointf point; - point.x = boost::lexical_cast(tokens[i]); - point.y = boost::lexical_cast(tokens[++i]); - this->values.push_back(point); - } - } catch (boost::bad_lexical_cast &e) { - printf("%s\n", e.what()); - return false; - } - - return true; - }; + bool deserialize(std::string str, bool append = false); }; class ConfigOptionBool : public ConfigOptionSingle diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 5a932bde7..c1b5870f9 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1,5 +1,6 @@ #include "PrintConfig.hpp" #include +#include #include namespace Slic3r { From d4136b38dffe55e7195a0e5b0bdab9801019c9ed Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 18 Mar 2017 12:22:08 -0500 Subject: [PATCH 68/96] Add manifest to Windows RC file (adapted from Strawberry Perl manifest). Fixes #3740 --- package/win/slic3r.exe.manifest | 32 ++++++++++++++++++++++++++++++++ package/win/slic3r.rc | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 package/win/slic3r.exe.manifest diff --git a/package/win/slic3r.exe.manifest b/package/win/slic3r.exe.manifest new file mode 100644 index 000000000..40c7d9e6b --- /dev/null +++ b/package/win/slic3r.exe.manifest @@ -0,0 +1,32 @@ + + + + Slic3r + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/win/slic3r.rc b/package/win/slic3r.rc index 3c1bfa4dd..20cfa265e 100644 --- a/package/win/slic3r.rc +++ b/package/win/slic3r.rc @@ -22,4 +22,4 @@ BEGIN VALUE "Translation", 0x409, 1252 END END - +1 Manifest slic3r.exe.manifest From 72681aca01a108898666f8c71d655c93230c8a9a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 19:08:38 +0100 Subject: [PATCH 69/96] Don't perform CPAN tests for IO::Scalar. #3573 --- Build.PL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build.PL b/Build.PL index ad5147adb..b7df2b192 100644 --- a/Build.PL +++ b/Build.PL @@ -129,7 +129,7 @@ EOF # temporary workaround for upstream bug in test push @cmd, '--notest' - if $module =~ /^(?:OpenGL|Math::PlanePath|Test::Harness)$/; + if $module =~ /^(?:OpenGL|Math::PlanePath|Test::Harness|IO::Scalar)$/; push @cmd, "$module~$version"; my $res = system @cmd; From 76f60471afb5a5fc378065d8266b59cc71937ddc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 18 Mar 2017 19:51:07 +0100 Subject: [PATCH 70/96] Moved typedefs to FillRectilinear.cpp --- xs/src/libslic3r/Fill/FillRectilinear.cpp | 21 +++++++++++++++++++++ xs/src/libslic3r/Fill/FillRectilinear.hpp | 21 --------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/xs/src/libslic3r/Fill/FillRectilinear.cpp b/xs/src/libslic3r/Fill/FillRectilinear.cpp index 2d3c84eb0..c74da2877 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.cpp @@ -63,6 +63,27 @@ FillRectilinear::_fill_single_direction(ExPolygon expolygon, // Whenever between two intersection points we find vertices of the original polygon, // store them in the 'skipped' member of the latter point. + struct IntersectionPoint : Point { + enum ipType { ipTypeLower, ipTypeUpper, ipTypeMiddle }; + ipType type; + + // skipped contains the polygon points accumulated between the previous intersection + // point and the current one, in the original polygon winding order (does not contain + // either points) + Points skipped; + + // next contains a polygon portion connecting this point to the first intersection + // point found following the polygon in any direction but having: + // x > this->x || (x == this->x && y > this->y) + // (it doesn't contain *this but it contains the target intersection point) + Points next; + + IntersectionPoint() : Point() {}; + IntersectionPoint(coord_t x, coord_t y, ipType _type) : Point(x,y), type(_type) {}; + }; + typedef std::map vertical_t; // + typedef std::map grid_t; // > + grid_t grid; { const Polygons polygons = expolygon; diff --git a/xs/src/libslic3r/Fill/FillRectilinear.hpp b/xs/src/libslic3r/Fill/FillRectilinear.hpp index d5d5b8ecf..11e3ec4a6 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.hpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.hpp @@ -23,27 +23,6 @@ protected: void _fill_single_direction(ExPolygon expolygon, const direction_t &direction, coord_t x_shift, Polylines* out); - - struct IntersectionPoint : Point { - enum ipType { ipTypeLower, ipTypeUpper, ipTypeMiddle }; - ipType type; - - // skipped contains the polygon points accumulated between the previous intersection - // point and the current one, in the original polygon winding order (does not contain - // either points) - Points skipped; - - // next contains a polygon portion connecting this point to the first intersection - // point found following the polygon in any direction but having: - // x > this->x || (x == this->x && y > this->y) - // (it doesn't contain *this but it contains the target intersection point) - Points next; - - IntersectionPoint() : Point() {}; - IntersectionPoint(coord_t x, coord_t y, ipType _type) : Point(x,y), type(_type) {}; - }; - typedef std::map vertical_t; // - typedef std::map grid_t; // > }; class FillAlignedRectilinear : public FillRectilinear From ad666beac0e0c5301312aaec320d614d942ca318 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 19 Mar 2017 01:40:18 +0100 Subject: [PATCH 71/96] Ported GCodeReader and SpiralVase to C++ --- lib/Slic3r.pm | 1 - lib/Slic3r/GCode/SpiralVase.pm | 88 ------------------------- lib/Slic3r/Print/GCode.pm | 4 +- src/CMakeLists.txt | 2 + xs/MANIFEST | 2 + xs/src/libslic3r/GCode/SpiralVase.cpp | 95 +++++++++++++++++++++++++++ xs/src/libslic3r/GCode/SpiralVase.hpp | 29 ++++++++ xs/src/libslic3r/GCodeReader.cpp | 91 +++++++++++++++++++++++++ xs/src/libslic3r/GCodeReader.hpp | 64 ++++++++++++++++++ xs/src/perlglue.cpp | 1 + xs/xsp/GCode.xsp | 13 ++++ xs/xsp/my.map | 4 ++ 12 files changed, 303 insertions(+), 91 deletions(-) delete mode 100644 lib/Slic3r/GCode/SpiralVase.pm create mode 100644 xs/src/libslic3r/GCode/SpiralVase.cpp create mode 100644 xs/src/libslic3r/GCode/SpiralVase.hpp create mode 100644 xs/src/libslic3r/GCodeReader.cpp create mode 100644 xs/src/libslic3r/GCodeReader.hpp diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 294b623ec..ca09d71f9 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -56,7 +56,6 @@ use Slic3r::GCode::ArcFitting; use Slic3r::GCode::MotionPlanner; use Slic3r::GCode::PressureRegulator; use Slic3r::GCode::Reader; -use Slic3r::GCode::SpiralVase; use Slic3r::GCode::VibrationLimit; use Slic3r::Geometry qw(PI); use Slic3r::Geometry::Clipper; diff --git a/lib/Slic3r/GCode/SpiralVase.pm b/lib/Slic3r/GCode/SpiralVase.pm deleted file mode 100644 index d35e29e71..000000000 --- a/lib/Slic3r/GCode/SpiralVase.pm +++ /dev/null @@ -1,88 +0,0 @@ -package Slic3r::GCode::SpiralVase; -use Moo; - -has 'config' => (is => 'ro', required => 1); -has 'enable' => (is => 'rw', default => sub { 0 }); -has 'reader' => (is => 'ro', default => sub { Slic3r::GCode::Reader->new }); - -use Slic3r::Geometry qw(unscale); - -sub BUILD { - my ($self) = @_; - - $self->reader->Z($self->config->z_offset); - $self->reader->apply_print_config($self->config); -} - -sub process_layer { - my $self = shift; - my ($gcode) = @_; - - # This post-processor relies on several assumptions: - # - all layers are processed through it, including those that are not supposed - # to be transformed, in order to update the reader with the XY positions - # - each call to this method includes a full layer, with a single Z move - # at the beginning - # - each layer is composed by suitable geometry (i.e. a single complete loop) - # - loops were not clipped before calling this method - - # if we're not going to modify G-code, just feed it to the reader - # in order to update positions - if (!$self->enable) { - $self->reader->parse($gcode, sub {}); - return $gcode; - } - - # get total XY length for this layer by summing all extrusion moves - my $total_layer_length = 0; - my $layer_height = 0; - my $z = undef; - $self->reader->clone->parse($gcode, sub { - my ($reader, $cmd, $args, $info) = @_; - - if ($cmd eq 'G1') { - if ($info->{extruding}) { - $total_layer_length += $info->{dist_XY}; - } elsif (exists $args->{Z}) { - $layer_height += $info->{dist_Z}; - $z //= $args->{Z}; - } - } - }); - - #use XXX; XXX [ $gcode, $layer_height, $z, $total_layer_length ]; - # remove layer height from initial Z - $z -= $layer_height; - - my $new_gcode = ""; - $self->reader->parse($gcode, sub { - my ($reader, $cmd, $args, $info) = @_; - - if ($cmd eq 'G1' && exists $args->{Z}) { - # if this is the initial Z move of the layer, replace it with a - # (redundant) move to the last Z of previous layer - my $line = $info->{raw}; - $line =~ s/ Z[.0-9]+/ Z$z/; - $new_gcode .= "$line\n"; - } elsif ($cmd eq 'G1' && !exists($args->{Z}) && $info->{dist_XY}) { - # horizontal move - my $line = $info->{raw}; - if ($info->{extruding}) { - $z += $info->{dist_XY} * $layer_height / $total_layer_length; - $line =~ s/^G1 /sprintf 'G1 Z%.3f ', $z/e; - $new_gcode .= "$line\n"; - } - # skip travel moves: the move to first perimeter point will - # cause a visible seam when loops are not aligned in XY; by skipping - # it we blend the first loop move in the XY plane (although the smoothness - # of such blend depend on how long the first segment is; maybe we should - # enforce some minimum length?) - } else { - $new_gcode .= "$info->{raw}\n"; - } - }); - - return $new_gcode; -} - -1; diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 261769716..9a653e89d 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -48,7 +48,7 @@ sub BUILD { $self->_cooling_buffer(Slic3r::GCode::CoolingBuffer->new($self->_gcodegen)); - $self->_spiral_vase(Slic3r::GCode::SpiralVase->new(config => $self->config)) + $self->_spiral_vase(Slic3r::GCode::SpiralVase->new($self->config)) if $self->config->spiral_vase; $self->_vibration_limit(Slic3r::GCode::VibrationLimit->new(config => $self->config)) @@ -323,7 +323,7 @@ sub process_layer { # check whether we're going to apply spiralvase logic if (defined $self->_spiral_vase) { - $self->_spiral_vase->enable( + $self->_spiral_vase->set_enable( $layer->id > 0 && ($self->print->config->skirts == 0 || ($layer->id >= $self->print->config->skirt_height && !$self->print->has_infinite_skirt)) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f3d4f4629..85e98471e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,8 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/Flow.cpp ${LIBDIR}/libslic3r/GCode.cpp ${LIBDIR}/libslic3r/GCode/CoolingBuffer.cpp + ${LIBDIR}/libslic3r/GCode/SpiralVase.cpp + ${LIBDIR}/libslic3r/GCodeReader.cpp ${LIBDIR}/libslic3r/GCodeSender.cpp ${LIBDIR}/libslic3r/GCodeWriter.cpp ${LIBDIR}/libslic3r/Geometry.cpp diff --git a/xs/MANIFEST b/xs/MANIFEST index 3b89458d3..a2ffbba5a 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -66,6 +66,8 @@ src/libslic3r/GCode.cpp src/libslic3r/GCode.hpp src/libslic3r/GCode/CoolingBuffer.cpp src/libslic3r/GCode/CoolingBuffer.hpp +src/libslic3r/GCode/SpiralVase.cpp +src/libslic3r/GCode/SpiralVase.hpp src/libslic3r/GCodeSender.cpp src/libslic3r/GCodeSender.hpp src/libslic3r/GCodeWriter.cpp diff --git a/xs/src/libslic3r/GCode/SpiralVase.cpp b/xs/src/libslic3r/GCode/SpiralVase.cpp new file mode 100644 index 000000000..b56c9e58b --- /dev/null +++ b/xs/src/libslic3r/GCode/SpiralVase.cpp @@ -0,0 +1,95 @@ +#include "SpiralVase.hpp" +#include + +namespace Slic3r { + +std::string +_format_z(float z) +{ + std::ostringstream ss; + ss << std::fixed << std::setprecision(3) + << z; + return ss.str(); +} + +std::string +SpiralVase::process_layer(const std::string &gcode) +{ + /* This post-processor relies on several assumptions: + - all layers are processed through it, including those that are not supposed + to be transformed, in order to update the reader with the XY positions + - each call to this method includes a full layer, with a single Z move + at the beginning + - each layer is composed by suitable geometry (i.e. a single complete loop) + - loops were not clipped before calling this method */ + + // If we're not going to modify G-code, just feed it to the reader + // in order to update positions. + if (!this->enable) { + this->_reader.parse(gcode, {}); + return gcode; + } + + // Get total XY length for this layer by summing all extrusion moves. + float total_layer_length = 0; + float layer_height = 0; + float z; + bool set_z = false; + + { + GCodeReader r = this->_reader; // clone + r.parse(gcode, [&total_layer_length, &layer_height, &z, &set_z] + (GCodeReader &, GCodeReader::GCodeLine &line) { + if (line.cmd == "G1") { + if (line.extruding()) { + total_layer_length += line.dist_XY(); + } else if (line.has('Z')) { + layer_height += line.dist_Z(); + if (!set_z) { + z = line.new_Z(); + set_z = true; + } + } + } + }); + } + + // Remove layer height from initial Z. + z -= layer_height; + + std::string new_gcode; + this->_reader.parse(gcode, [&new_gcode, &z, &layer_height, &total_layer_length] + (GCodeReader &, GCodeReader::GCodeLine line) { + if (line.cmd == "G1") { + if (line.has('Z')) { + // If this is the initial Z move of the layer, replace it with a + // (redundant) move to the last Z of previous layer. + line.set('Z', _format_z(z)); + new_gcode += line.raw + '\n'; + return; + } else { + float dist_XY = line.dist_XY(); + if (dist_XY > 0) { + // horizontal move + if (line.extruding()) { + z += dist_XY * layer_height / total_layer_length; + line.set('Z', _format_z(z)); + new_gcode += line.raw + '\n'; + } + return; + + /* Skip travel moves: the move to first perimeter point will + cause a visible seam when loops are not aligned in XY; by skipping + it we blend the first loop move in the XY plane (although the smoothness + of such blend depend on how long the first segment is; maybe we should + enforce some minimum length?). */ + } + } + } + new_gcode += line.raw + '\n'; + }); + + return new_gcode; +} + +} diff --git a/xs/src/libslic3r/GCode/SpiralVase.hpp b/xs/src/libslic3r/GCode/SpiralVase.hpp new file mode 100644 index 000000000..f14d15879 --- /dev/null +++ b/xs/src/libslic3r/GCode/SpiralVase.hpp @@ -0,0 +1,29 @@ +#ifndef slic3r_SpiralVase_hpp_ +#define slic3r_SpiralVase_hpp_ + +#include "libslic3r.h" +#include "GCode.hpp" +#include "GCodeReader.hpp" + +namespace Slic3r { + +class SpiralVase { + public: + bool enable; + + SpiralVase(const PrintConfig &config) + : enable(false), _config(&config) + { + this->_reader.Z = this->_config->z_offset; + this->_reader.apply_config(*this->_config); + }; + std::string process_layer(const std::string &gcode); + + private: + const PrintConfig* _config; + GCodeReader _reader; +}; + +} + +#endif diff --git a/xs/src/libslic3r/GCodeReader.cpp b/xs/src/libslic3r/GCodeReader.cpp new file mode 100644 index 000000000..fcaaea9be --- /dev/null +++ b/xs/src/libslic3r/GCodeReader.cpp @@ -0,0 +1,91 @@ +#include "GCodeReader.hpp" +#include +#include +#include + +namespace Slic3r { + +void +GCodeReader::apply_config(const PrintConfigBase &config) +{ + this->_config.apply(config, true); + this->_extrusion_axis = this->_config.get_extrusion_axis()[0]; +} + +void +GCodeReader::parse(const std::string &gcode, callback_t callback) +{ + std::istringstream ss(gcode); + std::string line; + while (std::getline(ss, line)) { + GCodeLine gline(this); + gline.raw = line; + if (this->verbose) + std::cout << line << std::endl; + + // strip comment + { + size_t pos = line.find(';'); + if (pos != std::string::npos) { + gline.comment = line.substr(pos+1); + line.erase(pos); + } + } + + // command and args + { + std::vector args; + boost::split(args, line, boost::is_any_of(" ")); + + // first one is cmd + gline.cmd = args.front(); + args.erase(args.begin()); + + for (std::string &arg : args) { + if (arg.size() < 2) continue; + gline.args.insert(std::make_pair(arg[0], arg.substr(1))); + } + } + + // convert extrusion axis + if (this->_extrusion_axis != 'E') { + const auto it = gline.args.find(this->_extrusion_axis); + if (it != gline.args.end()) { + std::swap(gline.args['E'], it->second); + gline.args.erase(it); + } + } + + if (callback) callback(*this, gline); + + // update coordinates + if (gline.cmd == "G0" || gline.cmd == "G1" || gline.cmd == "G92") { + this->X = gline.new_X(); + this->Y = gline.new_Y(); + this->Z = gline.new_Z(); + this->E = gline.new_E(); + this->F = gline.new_F(); + } + } +} + +void +GCodeReader::GCodeLine::set(char arg, std::string value) +{ + const std::string space(" "); + if (this->has(arg)) { + size_t pos = this->raw.find(space + arg)+2; + size_t end = this->raw.find(' ', pos+1); + this->raw = this->raw.replace(pos, end-pos, value); + } else { + size_t pos = this->raw.find(' '); + if (pos == std::string::npos) { + this->raw += space + arg + value; + } else { + this->raw = this->raw.replace(pos, 0, space + arg + value); + } + } + this->args[arg] = value; +} + +} diff --git a/xs/src/libslic3r/GCodeReader.hpp b/xs/src/libslic3r/GCodeReader.hpp new file mode 100644 index 000000000..267ac0e18 --- /dev/null +++ b/xs/src/libslic3r/GCodeReader.hpp @@ -0,0 +1,64 @@ +#ifndef slic3r_GCodeReader_hpp_ +#define slic3r_GCodeReader_hpp_ + +#include "libslic3r.h" +#include +#include +#include +#include +#include "PrintConfig.hpp" + +namespace Slic3r { + +class GCodeReader; +class GCodeReader { + public: + + class GCodeLine { + public: + GCodeReader* reader; + std::string raw; + std::string cmd; + std::string comment; + std::map args; + + GCodeLine(GCodeReader* _reader) : reader(_reader) {}; + + bool has(char arg) const { return this->args.count(arg) > 0; }; + float new_X() const { return this->has('X') ? atof(this->args.at('X').c_str()) : this->reader->X; }; + float new_Y() const { return this->has('Y') ? atof(this->args.at('Y').c_str()) : this->reader->Y; }; + float new_Z() const { return this->has('Z') ? atof(this->args.at('Z').c_str()) : this->reader->Z; }; + float new_E() const { return this->has('E') ? atof(this->args.at('E').c_str()) : this->reader->E; }; + float new_F() const { return this->has('F') ? atof(this->args.at('F').c_str()) : this->reader->F; }; + float dist_X() const { return this->new_X() - this->reader->X; }; + float dist_Y() const { return this->new_Y() - this->reader->Y; }; + float dist_Z() const { return this->new_Z() - this->reader->Z; }; + float dist_E() const { return this->new_E() - this->reader->E; }; + float dist_XY() const { + float x = this->dist_X(); + float y = this->dist_Y(); + return sqrt(x*x + y*y); + }; + bool extruding() const { return this->cmd == "G1" && this->dist_E() > 0; }; + bool retracting() const { return this->cmd == "G1" && this->dist_E() < 0; }; + bool travel() const { return this->cmd == "G1" && !this->has('E'); }; + void set(char arg, std::string value); + }; + typedef std::function callback_t; + + float X, Y, Z, E, F; + bool verbose; + callback_t callback; + + GCodeReader() : X(0), Y(0), Z(0), E(0), F(0), verbose(false), _extrusion_axis('E') {}; + void apply_config(const PrintConfigBase &config); + void parse(const std::string &gcode, callback_t callback); + + private: + GCodeConfig _config; + char _extrusion_axis; +}; + +} /* namespace Slic3r */ + +#endif /* slic3r_GCodeReader_hpp_ */ diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index 3c08d6144..9ce012a36 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -15,6 +15,7 @@ REGISTER_CLASS(Filler, "Filler"); REGISTER_CLASS(AvoidCrossingPerimeters, "GCode::AvoidCrossingPerimeters"); REGISTER_CLASS(CoolingBuffer, "GCode::CoolingBuffer"); REGISTER_CLASS(OozePrevention, "GCode::OozePrevention"); +REGISTER_CLASS(SpiralVase, "GCode::SpiralVase"); REGISTER_CLASS(Wipe, "GCode::Wipe"); REGISTER_CLASS(GCode, "GCode"); REGISTER_CLASS(GCodeSender, "GCode::Sender"); diff --git a/xs/xsp/GCode.xsp b/xs/xsp/GCode.xsp index 579951c73..f73ca4442 100644 --- a/xs/xsp/GCode.xsp +++ b/xs/xsp/GCode.xsp @@ -4,6 +4,7 @@ #include #include "libslic3r/GCode.hpp" #include "libslic3r/GCode/CoolingBuffer.hpp" +#include "libslic3r/GCode/SpiralVase.hpp" %} %name{Slic3r::GCode::AvoidCrossingPerimeters} class AvoidCrossingPerimeters { @@ -81,6 +82,18 @@ std::string flush(); }; +%name{Slic3r::GCode::SpiralVase} class SpiralVase { + SpiralVase(StaticPrintConfig* config) + %code{% RETVAL = new SpiralVase(*dynamic_cast(config)); %}; + ~SpiralVase(); + + bool enable() + %code{% RETVAL = THIS->enable; %}; + void set_enable(bool enable) + %code{% THIS->enable = enable; %}; + std::string process_layer(std::string gcode); +}; + %name{Slic3r::GCode} class GCode { GCode(); ~GCode(); diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 1ce5d719f..c47d79e00 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -198,6 +198,10 @@ CoolingBuffer* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T +SpiralVase* O_OBJECT_SLIC3R +Ref O_OBJECT_SLIC3R_T +Clone O_OBJECT_SLIC3R_T + GCode* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T From af8ae8d2680b575b00c9bbb4853ab68eaecd4b89 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 19 Mar 2017 00:22:17 -0500 Subject: [PATCH 72/96] Added single-object AMF export (with modifier meshes). Extended text on plate AMF export to indicate that it exports modifier meshes. --- lib/Slic3r/GUI/MainFrame.pm | 2 +- lib/Slic3r/GUI/Plater.pm | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index ddf67a28f..390ab2edb 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -249,7 +249,7 @@ sub _init_menubar { $self->_append_menu_item($self->{plater_menu}, "Export plate as STL...", 'Export current plate as STL', sub { $plater->export_stl; }, undef, 'brick_go.png'); - $self->_append_menu_item($self->{plater_menu}, "Export plate as AMF...", 'Export current plate as AMF', sub { + $self->_append_menu_item($self->{plater_menu}, "Export plate with modifiers as AMF...", 'Export current plate as AMF, including all modifier meshes', sub { $plater->export_amf; }, undef, 'brick_go.png'); $self->_append_menu_item($self->{plater_menu}, "Open DLP Projector…\tCtrl+L", 'Open projector window for DLP printing', sub { diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 74078f76d..7f6c21598 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1539,6 +1539,23 @@ sub export_object_stl { $self->statusbar->SetStatusText("STL file exported to $output_file"); } +# Export function for a single AMF output +sub export_object_amf { + my $self = shift; + + my ($obj_idx, $object) = $self->selected_object; + return if !defined $obj_idx; + + my $local_model = Slic3r::Model->new; + my $model_object = $self->{model}->objects->[$obj_idx]; + # copy model_object -> local_model + $local_model->add_object($model_object); + + my $output_file = $self->_get_export_file('AMF') or return; + $local_model->write_amf($output_file); + $self->statusbar->SetStatusText("AMF file exported to $output_file"); +} + sub export_amf { my $self = shift; @@ -2032,6 +2049,9 @@ sub object_menu { $frame->_append_menu_item($menu, "Export object as STL…", 'Export this single object as STL file', sub { $self->export_object_stl; }, undef, 'brick_go.png'); + $frame->_append_menu_item($menu, "Export object and modifiers as AMF…", 'Export this single object and all associated modifiers as AMF file', sub { + $self->export_object_amf; + }, undef, 'brick_go.png'); return $menu; } From dddbe64b866e10a7c88645faadb77a2508341d1e Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 19 Mar 2017 00:31:14 -0500 Subject: [PATCH 73/96] Restrict file types for model exports to what we are permitting (UX fix). Changed extension from .amf.xml -> .amf (common usage) Fixes #3774 --- lib/Slic3r/GUI.pm | 2 ++ lib/Slic3r/GUI/Plater.pm | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 7d2f7f26b..2459ef9c5 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -53,6 +53,8 @@ use constant FILE_WILDCARDS => { svg => 'SVG files *.svg|*.svg;*.SVG', }; use constant MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(known stl obj amf)}; +use constant STL_MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(stl)}; +use constant AMF_MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(amf)}; our $datadir; # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 7f6c21598..c72350def 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1570,14 +1570,21 @@ sub _get_export_file { my $self = shift; my ($format) = @_; - my $suffix = $format eq 'STL' ? '.stl' : '.amf.xml'; + my $suffix = $format eq 'STL' ? '.stl' : '.amf'; my $output_file = $main::opt{output}; { $output_file = $self->{print}->output_filepath($output_file // ''); $output_file =~ s/\.gcode$/$suffix/i; - my $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file), - basename($output_file), &Slic3r::GUI::MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + my $dlg; + $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file), + basename($output_file), &Slic3r::GUI::STL_MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT) + if $format eq 'STL'; + + $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file), + basename($output_file), &Slic3r::GUI::AMF_MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT) + if $format eq 'AMF'; + if ($dlg->ShowModal != wxID_OK) { $dlg->Destroy; return undef; From 52a94e8f404fe330bbd0a5cdbc5c40c2e1578ae9 Mon Sep 17 00:00:00 2001 From: Ranvir Singh Date: Mon, 20 Mar 2017 00:32:59 +0530 Subject: [PATCH 74/96] remove deprecated code and add new one (#3775) change auto_ptr to unique_ptr --- xs/src/libslic3r/Print.cpp | 2 +- xs/src/libslic3r/SLAPrint.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index a3007801d..be6f24f38 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -882,7 +882,7 @@ Print::_make_brim() } } - std::auto_ptr filler(Fill::new_from_type(ipRectilinear)); + std::unique_ptr filler(Fill::new_from_type(ipRectilinear)); filler->min_spacing = flow.spacing(); filler->dont_adjust = true; filler->density = 1; diff --git a/xs/src/libslic3r/SLAPrint.cpp b/xs/src/libslic3r/SLAPrint.cpp index 826e6184e..02043e191 100644 --- a/xs/src/libslic3r/SLAPrint.cpp +++ b/xs/src/libslic3r/SLAPrint.cpp @@ -57,7 +57,7 @@ SLAPrint::slice() // generate infill if (this->config.fill_density < 100) { - std::auto_ptr fill(Fill::new_from_type(this->config.fill_pattern.value)); + std::unique_ptr fill(Fill::new_from_type(this->config.fill_pattern.value)); fill->bounding_box.merge(Point::new_scale(bb.min.x, bb.min.y)); fill->bounding_box.merge(Point::new_scale(bb.max.x, bb.max.y)); fill->min_spacing = this->config.get_abs_value("infill_extrusion_width", this->config.layer_height.value); @@ -184,7 +184,7 @@ SLAPrint::_infill_layer(size_t i, const Fill* _fill) // Generate internal infill { - std::auto_ptr fill(_fill->clone()); + std::unique_ptr fill(_fill->clone()); fill->layer_id = i; fill->z = layer.print_z; From a19cc10b8e7f126a3f0f102716bb4d8536f3590f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 13:59:09 +0100 Subject: [PATCH 75/96] Bugfix: Controller was crashing on wxWidgets 2.8.x. #3159 --- .../GUI/Controller/ManualControlDialog.pm | 10 +++--- lib/Slic3r/GUI/Controller/PrinterPanel.pm | 32 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm index 224c5e069..37dec1634 100644 --- a/lib/Slic3r/GUI/Controller/ManualControlDialog.pm +++ b/lib/Slic3r/GUI/Controller/ManualControlDialog.pm @@ -193,18 +193,18 @@ sub new { my $sbsizer = Wx::StaticBoxSizer->new($box, wxVERTICAL); $right_sizer->Add($sbsizer, 1, wxEXPAND, 0); - my $log = $self->{log_textctrl} = Wx::TextCtrl->new($box, -1, "", wxDefaultPosition, wxDefaultSize, + my $log = $self->{log_textctrl} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxBORDER_NONE); - $log->SetBackgroundColour($box->GetBackgroundColour); + $log->SetBackgroundColour($self->GetBackgroundColour); $log->SetFont($Slic3r::GUI::small_font); $log->SetEditable(0); $sbsizer->Add($self->{log_textctrl}, 1, wxEXPAND, 0); my $cmd_sizer = Wx::BoxSizer->new(wxHORIZONTAL); - my $cmd_textctrl = Wx::TextCtrl->new($box, -1, ''); + my $cmd_textctrl = Wx::TextCtrl->new($self, -1, ''); $cmd_sizer->Add($cmd_textctrl, 1, wxEXPAND, 0); - my $btn = Wx::Button->new($box, -1, + my $btn = Wx::Button->new($self, -1, "Send", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); $btn->SetFont($Slic3r::GUI::small_font); if ($Slic3r::GUI::have_button_icons) { @@ -212,7 +212,7 @@ sub new { } $cmd_sizer->Add($btn, 0, wxEXPAND | wxLEFT, 5); - EVT_BUTTON($box, $btn, sub { + EVT_BUTTON($self, $btn, sub { return if $cmd_textctrl->GetValue eq ''; $self->sender->send($cmd_textctrl->GetValue, 1); $cmd_textctrl->SetValue(''); diff --git a/lib/Slic3r/GUI/Controller/PrinterPanel.pm b/lib/Slic3r/GUI/Controller/PrinterPanel.pm index 3f5fbf9c1..53850a69e 100644 --- a/lib/Slic3r/GUI/Controller/PrinterPanel.pm +++ b/lib/Slic3r/GUI/Controller/PrinterPanel.pm @@ -85,7 +85,7 @@ sub new { # printer name { - my $text = Wx::StaticText->new($box, -1, $self->printer_name, wxDefaultPosition, [220,-1]); + my $text = Wx::StaticText->new($self, -1, $self->printer_name, wxDefaultPosition, [220,-1]); my $font = $text->GetFont; $font->SetPointSize(20); $text->SetFont($font); @@ -99,19 +99,19 @@ sub new { $conn_sizer->AddGrowableCol(1, 1); $left_sizer->Add($conn_sizer, 0, wxEXPAND | wxTOP, 5); { - my $text = Wx::StaticText->new($box, -1, "Port:", wxDefaultPosition, wxDefaultSize); + my $text = Wx::StaticText->new($self, -1, "Port:", wxDefaultPosition, wxDefaultSize); $text->SetFont($Slic3r::GUI::small_font); $conn_sizer->Add($text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5); } my $serial_port_sizer = Wx::BoxSizer->new(wxHORIZONTAL); { - $self->{serial_port_combobox} = Wx::ComboBox->new($box, -1, $config->serial_port, wxDefaultPosition, wxDefaultSize, []); + $self->{serial_port_combobox} = Wx::ComboBox->new($self, -1, $config->serial_port, wxDefaultPosition, wxDefaultSize, []); $self->{serial_port_combobox}->SetFont($Slic3r::GUI::small_font); $self->update_serial_ports; $serial_port_sizer->Add($self->{serial_port_combobox}, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1); } { - $self->{btn_rescan_serial} = my $btn = Wx::BitmapButton->new($box, -1, Wx::Bitmap->new($Slic3r::var->("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), + $self->{btn_rescan_serial} = my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxDefaultSize, &Wx::wxBORDER_NONE); $btn->SetToolTipString("Rescan serial ports") if $btn->can('SetToolTipString'); @@ -121,19 +121,19 @@ sub new { $conn_sizer->Add($serial_port_sizer, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5); { - my $text = Wx::StaticText->new($box, -1, "Speed:", wxDefaultPosition, wxDefaultSize); + my $text = Wx::StaticText->new($self, -1, "Speed:", wxDefaultPosition, wxDefaultSize); $text->SetFont($Slic3r::GUI::small_font); $conn_sizer->Add($text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5); } my $serial_speed_sizer = Wx::BoxSizer->new(wxHORIZONTAL); { - $self->{serial_speed_combobox} = Wx::ComboBox->new($box, -1, $config->serial_speed, wxDefaultPosition, wxDefaultSize, + $self->{serial_speed_combobox} = Wx::ComboBox->new($self, -1, $config->serial_speed, wxDefaultPosition, wxDefaultSize, ["115200", "250000"]); $self->{serial_speed_combobox}->SetFont($Slic3r::GUI::small_font); $serial_speed_sizer->Add($self->{serial_speed_combobox}, 0, wxALIGN_CENTER_VERTICAL, 0); } { - $self->{btn_disconnect} = my $btn = Wx::Button->new($box, -1, "Disconnect", wxDefaultPosition, wxDefaultSize); + $self->{btn_disconnect} = my $btn = Wx::Button->new($self, -1, "Disconnect", wxDefaultPosition, wxDefaultSize); $btn->SetFont($Slic3r::GUI::small_font); if ($Slic3r::GUI::have_button_icons) { $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG)); @@ -146,7 +146,7 @@ sub new { # buttons { - $self->{btn_connect} = my $btn = Wx::Button->new($box, -1, "Connect to printer", wxDefaultPosition, [-1, 40]); + $self->{btn_connect} = my $btn = Wx::Button->new($self, -1, "Connect to printer", wxDefaultPosition, [-1, 40]); my $font = $btn->GetFont; $font->SetPointSize($font->GetPointSize + 2); $btn->SetFont($font); @@ -165,12 +165,12 @@ sub new { } # status - $self->{status_text} = Wx::StaticText->new($box, -1, "", wxDefaultPosition, [200,-1]); + $self->{status_text} = Wx::StaticText->new($self, -1, "", wxDefaultPosition, [200,-1]); $left_sizer->Add($self->{status_text}, 1, wxEXPAND | wxTOP, 15); # manual control { - $self->{btn_manual_control} = my $btn = Wx::Button->new($box, -1, "Manual control", wxDefaultPosition, wxDefaultSize); + $self->{btn_manual_control} = my $btn = Wx::Button->new($self, -1, "Manual control", wxDefaultPosition, wxDefaultSize); $btn->SetFont($Slic3r::GUI::small_font); if ($Slic3r::GUI::have_button_icons) { $btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG)); @@ -187,7 +187,7 @@ sub new { # temperature { - my $temp_panel = $self->{temp_panel} = Wx::Panel->new($box, -1); + my $temp_panel = $self->{temp_panel} = Wx::Panel->new($self, -1); my $temp_sizer = Wx::BoxSizer->new(wxHORIZONTAL); my $temp_font = Wx::Font->new($Slic3r::GUI::small_font); @@ -220,11 +220,11 @@ sub new { # print jobs panel $self->{print_jobs_sizer} = my $print_jobs_sizer = Wx::BoxSizer->new(wxVERTICAL); { - my $text = Wx::StaticText->new($box, -1, "Queue:", wxDefaultPosition, wxDefaultSize); + my $text = Wx::StaticText->new($self, -1, "Queue:", wxDefaultPosition, wxDefaultSize); $text->SetFont($Slic3r::GUI::small_font); $print_jobs_sizer->Add($text, 0, wxEXPAND, 0); - $self->{jobs_panel} = Wx::ScrolledWindow->new($box, -1, wxDefaultPosition, wxDefaultSize, + $self->{jobs_panel} = Wx::ScrolledWindow->new($self, -1, wxDefaultPosition, wxDefaultSize, wxVSCROLL | wxBORDER_NONE); $self->{jobs_panel}->SetScrollbars(0, 1, 0, 1); $self->{jobs_panel_sizer} = Wx::BoxSizer->new(wxVERTICAL); @@ -248,13 +248,13 @@ sub new { my $log_sizer = Wx::BoxSizer->new(wxVERTICAL); { - my $text = Wx::StaticText->new($box, -1, "Log:", wxDefaultPosition, wxDefaultSize); + my $text = Wx::StaticText->new($self, -1, "Log:", wxDefaultPosition, wxDefaultSize); $text->SetFont($Slic3r::GUI::small_font); $log_sizer->Add($text, 0, wxEXPAND, 0); - my $log = $self->{log_textctrl} = Wx::TextCtrl->new($box, -1, "", wxDefaultPosition, wxDefaultSize, + my $log = $self->{log_textctrl} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxBORDER_NONE); - $log->SetBackgroundColour($box->GetBackgroundColour); + $log->SetBackgroundColour($self->GetBackgroundColour); $log->SetFont($Slic3r::GUI::small_font); $log->SetEditable(0); $log_sizer->Add($self->{log_textctrl}, 1, wxEXPAND, 0); From 9dbe2eea37eb2b6a219bff7c12852df25d07bee8 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 15:46:22 +0100 Subject: [PATCH 76/96] Menu option for coloring toolpaths by extruder using the configured filament colors --- lib/Slic3r/GUI.pm | 1 + lib/Slic3r/GUI/3DScene.pm | 288 ++++++++++++++--------------- lib/Slic3r/GUI/MainFrame.pm | 30 ++- lib/Slic3r/GUI/Plater.pm | 120 ++++++------ lib/Slic3r/GUI/Plater/3DPreview.pm | 10 + lib/Slic3r/Print/GCode.pm | 6 +- xs/src/libslic3r/Print.cpp | 12 ++ xs/src/libslic3r/Print.hpp | 1 + xs/xsp/Print.xsp | 1 + 9 files changed, 256 insertions(+), 213 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 2459ef9c5..0ab411277 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -75,6 +75,7 @@ our $Settings = { # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. no_controller => 0, threads => $Slic3r::Config::Options->{threads}{default}, + color_toolpaths_by => 'role', }, }; diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 67046853f..7c9ae2dee 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -748,10 +748,10 @@ sub InitGL { # Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. glShadeModel(GL_SMOOTH); - glMaterialfv_p(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, 0.5, 0.3, 0.3, 1); + glMaterialfv_p(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, 0.3, 0.3, 0.3, 1); glMaterialfv_p(GL_FRONT_AND_BACK, GL_SPECULAR, 1, 1, 1, 1); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50); - glMaterialfv_p(GL_FRONT_AND_BACK, GL_EMISSION, 0.1, 0, 0, 0.9); + glMaterialfv_p(GL_FRONT_AND_BACK, GL_EMISSION, 0.1, 0.1, 0.1, 0.9); # A handy trick -- have surface material mirror the color. glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); @@ -1152,21 +1152,25 @@ use List::Util qw(first min max); use Slic3r::Geometry qw(scale unscale epsilon); use Slic3r::Print::State ':steps'; -use constant COLORS => [ [1,1,0,1], [1,0.5,0.5,1], [0.5,1,0.5,1], [0.5,0.5,1,1] ]; - __PACKAGE__->mk_accessors(qw( + colors color_by + color_toolpaths_by select_by drag_by volumes_by_object _objects_by_volumes )); +sub default_colors { [1,0.95,0.2,1], [1,0.45,0.45,1], [0.5,1,0.5,1], [0.5,0.5,1,1] } + sub new { my $class = shift; my $self = $class->SUPER::new(@_); + $self->colors([ $self->default_colors ]); $self->color_by('volume'); # object | volume + $self->color_toolpaths_by('role'); # role | extruder $self->select_by('object'); # object | volume | instance $self->drag_by('instance'); # object | instance $self->volumes_by_object({}); # obj_idx => [ volume_idx, volume_idx ... ] @@ -1204,7 +1208,7 @@ sub load_object { $color_idx = $obj_idx; } - my $color = [ @{COLORS->[ $color_idx % scalar(@{&COLORS}) ]} ]; + my $color = [ @{$self->colors->[ $color_idx % scalar(@{$self->colors}) ]} ]; $color->[3] = $volume->modifier ? 0.5 : 1; push @{$self->volumes}, my $v = Slic3r::GUI::3DScene::Volume->new( bounding_box => $mesh->bounding_box, @@ -1281,7 +1285,7 @@ sub load_print_object_slices { push @{$self->volumes}, my $v = Slic3r::GUI::3DScene::Volume->new( bounding_box => $bb, - color => COLORS->[0], + color => $self->colors->[0], verts => OpenGL::Array->new_list(GL_FLOAT, @verts), norms => OpenGL::Array->new_list(GL_FLOAT, @norms), quad_verts => OpenGL::Array->new_list(GL_FLOAT, @quad_verts), @@ -1299,66 +1303,75 @@ sub load_print_toolpaths { && $print->config->interior_brim_width == 0 && $print->config->brim_connections_width == 0; - my $qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - my $tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - my %offsets = (); # print_z => [ qverts, tverts ] - - my $skirt_height = 0; # number of layers - if ($print->has_infinite_skirt) { - $skirt_height = $print->total_layer_count; - } else { - $skirt_height = min($print->config->skirt_height, $print->total_layer_count); - } - $skirt_height ||= 1 if $print->config->brim_width > 0 || $print->config->interior_brim_width; - - # get first $skirt_height layers (maybe this should be moved to a PrintObject method?) - my $object0 = $print->get_object(0); - my @layers = (); - push @layers, map $object0->get_layer($_-1), 1..min($skirt_height, $object0->layer_count); - push @layers, map $object0->get_support_layer($_-1), 1..min($skirt_height, $object0->support_layer_count); - @layers = sort { $a->print_z <=> $b->print_z } @layers; - @layers = @layers[0..($skirt_height-1)]; - - foreach my $i (0..($skirt_height-1)) { - my $top_z = $layers[$i]->print_z; - $offsets{$top_z} = [$qverts->size, $tverts->size]; - - if ($i == 0) { - $self->_extrusionentity_to_verts($print->brim, $top_z, Slic3r::Point->new(0,0), $qverts, $tverts); - } - - $self->_extrusionentity_to_verts($print->skirt, $top_z, Slic3r::Point->new(0,0), $qverts, $tverts); - } - my $bb = Slic3r::Geometry::BoundingBoxf3->new; { my $pbb = $print->bounding_box; $bb->merge_point(Slic3r::Pointf3->new_unscale(@{$pbb->min_point})); $bb->merge_point(Slic3r::Pointf3->new_unscale(@{$pbb->max_point})); } - push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( - bounding_box => $bb, - color => COLORS->[2], - qverts => $qverts, - tverts => $tverts, - offsets => { %offsets }, - ); + + my $color_by_extruder = $self->color_toolpaths_by eq 'extruder'; + + if (!$print->brim->empty) { + my $color = $color_by_extruder + ? $self->colors->[ ($print->brim_extruder-1) % @{$self->colors} ] + : $self->colors->[2]; + + push @{$self->volumes}, my $volume = Slic3r::GUI::3DScene::Volume->new( + bounding_box => $bb, + color => $color, + qverts => Slic3r::GUI::_3DScene::GLVertexArray->new, + tverts => Slic3r::GUI::_3DScene::GLVertexArray->new, + offsets => {}, # print_z => [ qverts, tverts ] + ); + + my $top_z = $print->get_object(0)->get_layer(0)->print_z; + $volume->offsets->{$top_z} = [0, 0]; + $self->_extrusionentity_to_verts($print->brim, $top_z, Slic3r::Point->new(0,0), + $volume->qverts, $volume->tverts); + } + + if (!$print->skirt->empty) { + # TODO: it's a bit difficult to predict skirt extruders with the current skirt logic. + # We need to rewrite it anyway. + my $color = +($self->default_colors)[0]; + push @{$self->volumes}, my $volume = Slic3r::GUI::3DScene::Volume->new( + bounding_box => $bb, + color => $color, + qverts => Slic3r::GUI::_3DScene::GLVertexArray->new, + tverts => Slic3r::GUI::_3DScene::GLVertexArray->new, + offsets => {}, # print_z => [ qverts, tverts ] + ); + + my $skirt_height = 0; # number of layers + if ($print->has_infinite_skirt) { + $skirt_height = $print->total_layer_count; + } else { + $skirt_height = min($print->config->skirt_height, $print->total_layer_count); + } + $skirt_height ||= 1 if $print->config->brim_width > 0 || $print->config->interior_brim_width; + + # get first $skirt_height layers (maybe this should be moved to a PrintObject method?) + my $object0 = $print->get_object(0); + my @layers = (); + push @layers, map $object0->get_layer($_-1), 1..min($skirt_height, $object0->layer_count); + push @layers, map $object0->get_support_layer($_-1), 1..min($skirt_height, $object0->support_layer_count); + @layers = sort { $a->print_z <=> $b->print_z } @layers; + @layers = @layers[0..($skirt_height-1)]; + + foreach my $i (0..($skirt_height-1)) { + my $top_z = $layers[$i]->print_z; + $volume->offsets->{$top_z} = [$volume->qverts->size, $volume->tverts->size]; + + $self->_extrusionentity_to_verts($print->skirt, $top_z, Slic3r::Point->new(0,0), + $volume->qverts, $volume->tverts); + } + } } sub load_print_object_toolpaths { my ($self, $object) = @_; - my $perim_qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - my $perim_tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - my $infill_qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - my $infill_tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - my $support_qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - my $support_tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - - my %perim_offsets = (); # print_z => [ qverts, tverts ] - my %infill_offsets = (); - my %support_offsets = (); - # order layers by print_z my @layers = sort { $a->print_z <=> $b->print_z } @{$object->layers}, @{$object->support_layers}; @@ -1374,122 +1387,91 @@ sub load_print_object_toolpaths { $bb->merge_point(Slic3r::Pointf3->new_unscale(@{$cbb->max_point}, $object->size->z)); } } - + + my %volumes = (); # color => Volume + # Maximum size of an allocation block: 32MB / sizeof(float) my $alloc_size_max = 32 * 1048576 / 4; + my $add = sub { + my ($coll, $top_z, $copy, $color) = @_; + + my $volume = $volumes{$color}; + if (!$volume) { + push @{$self->volumes}, $volumes{$color} = $volume = Slic3r::GUI::3DScene::Volume->new( + bounding_box => $bb, + color => $color, + qverts => Slic3r::GUI::_3DScene::GLVertexArray->new, + tverts => Slic3r::GUI::_3DScene::GLVertexArray->new, + offsets => {}, # print_z => [ qverts, tverts ] + ); + } + + $volume->offsets->{$top_z} //= [ $volume->qverts->size, $volume->tverts->size ]; + $self->_extrusionentity_to_verts($coll, $top_z, $copy, $volume->qverts, $volume->tverts); + }; + + my $color_by_extruder = $self->color_toolpaths_by eq 'extruder'; + foreach my $layer (@layers) { my $top_z = $layer->print_z; - - if (!exists $perim_offsets{$top_z}) { - $perim_offsets{$top_z} = [ - $perim_qverts->size, $perim_tverts->size, - ]; - } - if (!exists $infill_offsets{$top_z}) { - $infill_offsets{$top_z} = [ - $infill_qverts->size, $infill_tverts->size, - ]; - } - if (!exists $support_offsets{$top_z}) { - $support_offsets{$top_z} = [ - $support_qverts->size, $support_tverts->size, - ]; - } - foreach my $copy (@{ $object->_shifted_copies }) { foreach my $layerm (@{$layer->regions}) { if ($object->step_done(STEP_PERIMETERS)) { - $self->_extrusionentity_to_verts($layerm->perimeters, $top_z, $copy, - $perim_qverts, $perim_tverts); + my $color = $color_by_extruder + ? $self->colors->[ ($layerm->region->config->perimeter_extruder-1) % @{$self->colors} ] + : $self->colors->[0]; + $add->($layerm->perimeters, $top_z, $copy, $color); } if ($object->step_done(STEP_INFILL)) { - $self->_extrusionentity_to_verts($layerm->fills, $top_z, $copy, - $infill_qverts, $infill_tverts); + my $color = $color_by_extruder + ? $self->colors->[ ($layerm->region->config->infill_extruder-1) % @{$self->colors} ] + : $self->colors->[1]; + + if ($color_by_extruder && $layerm->region->config->infill_extruder != $layerm->region->config->solid_infill_extruder) { + # divide solid and non-solid infill + my $solid = Slic3r::ExtrusionPath::Collection->new; + my $non_solid = Slic3r::ExtrusionPath::Collection->new; + foreach my $fill (@{$layerm->fills}) { + if ($fill->[0]->is_solid_infill) { + $solid->append($fill); + } else { + $non_solid->append($fill); + } + } + $add->($non_solid, $top_z, $copy, $color); + $color = $self->colors->[ ($layerm->region->config->solid_infill_extruder-1) % @{&COLORS} ]; + $add->($solid, $top_z, $copy, $color); + } else { + $add->($layerm->fills, $top_z, $copy, $color); + } } } if ($layer->isa('Slic3r::Layer::Support') && $object->step_done(STEP_SUPPORTMATERIAL)) { - $self->_extrusionentity_to_verts($layer->support_fills, $top_z, $copy, - $support_qverts, $support_tverts); - - $self->_extrusionentity_to_verts($layer->support_interface_fills, $top_z, $copy, - $support_qverts, $support_tverts); + { + my $color = $color_by_extruder + ? $self->colors->[ ($layer->object->config->support_material_extruder-1) % @{$self->colors} ] + : $self->colors->[2]; + $add->($layer->support_fills, $top_z, $copy, $color); + } + { + my $color = ($color_by_extruder) + ? $self->colors->[ ($layer->object->config->support_material_interface_extruder-1) % @{$self->colors} ] + : $self->colors->[2]; + $add->($layer->support_interface_fills, $top_z, $copy, $color); + } } } - - if ($perim_qverts->size() > $alloc_size_max || $perim_tverts->size() > $alloc_size_max) { - # Store the vertex arrays and restart their containers. - push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( - bounding_box => $bb, - color => COLORS->[0], - qverts => $perim_qverts, - tverts => $perim_tverts, - offsets => { %perim_offsets }, - ); - $perim_qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - $perim_tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - %perim_offsets = (); + + foreach my $color (keys %volumes) { + my $volume = $volumes{$color}; + if ($volume->qverts->size() > $alloc_size_max || $volume->tverts->size() > $alloc_size_max) { + # stop appending to this volume; create a new one next time + delete $volumes{$color}; + } } - - if ($infill_qverts->size() > $alloc_size_max || $infill_tverts->size() > $alloc_size_max) { - # Store the vertex arrays and restart their containers. - push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( - bounding_box => $bb, - color => COLORS->[1], - qverts => $infill_qverts, - tverts => $infill_tverts, - offsets => { %infill_offsets }, - ); - $infill_qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - $infill_tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - %infill_offsets = (); - } - - if ($support_qverts->size() > $alloc_size_max || $support_tverts->size() > $alloc_size_max) { - # Store the vertex arrays and restart their containers. - push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( - bounding_box => $bb, - color => COLORS->[2], - qverts => $support_qverts, - tverts => $support_tverts, - offsets => { %support_offsets }, - ); - $support_qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - $support_tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; - %support_offsets = (); - } - } - - if ($perim_qverts->size() > 0 || $perim_tverts->size() > 0) { - push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( - bounding_box => $bb, - color => COLORS->[0], - qverts => $perim_qverts, - tverts => $perim_tverts, - offsets => { %perim_offsets }, - ); - } - - if ($infill_qverts->size() > 0 || $infill_tverts->size() > 0) { - push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( - bounding_box => $bb, - color => COLORS->[1], - qverts => $infill_qverts, - tverts => $infill_tverts, - offsets => { %infill_offsets }, - ); - } - - if ($support_qverts->size() > 0 || $support_tverts->size() > 0) { - push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( - bounding_box => $bb, - color => COLORS->[2], - qverts => $support_qverts, - tverts => $support_tverts, - offsets => { %support_offsets }, - ); } } diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 390ab2edb..92ee27954 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -303,6 +303,32 @@ sub _init_menubar { $self->_append_menu_item($self->{viewMenu}, "Rear" , 'Rear View' , sub { $self->select_view('rear' ); }); $self->_append_menu_item($self->{viewMenu}, "Left" , 'Left View' , sub { $self->select_view('left' ); }); $self->_append_menu_item($self->{viewMenu}, "Right" , 'Right View' , sub { $self->select_view('right' ); }); + $self->{viewMenu}->AppendSeparator(); + $self->{color_toolpaths_by_role} = $self->_append_menu_item($self->{viewMenu}, + "Color Toolpaths by Role", + 'Color toolpaths according to perimeter/infill/support material', + sub { + $Slic3r::GUI::Settings->{_}{color_toolpaths_by} = 'role'; + wxTheApp->save_settings; + $self->{plater}{preview3D}->reload_print; + }, + undef, undef, wxITEM_RADIO + ); + $self->{color_toolpaths_by_extruder} = $self->_append_menu_item($self->{viewMenu}, + "Color Toolpaths by Filament", + 'Color toolpaths using the configured extruder/filament color', + sub { + $Slic3r::GUI::Settings->{_}{color_toolpaths_by} = 'extruder'; + wxTheApp->save_settings; + $self->{plater}{preview3D}->reload_print; + }, + undef, undef, wxITEM_RADIO + ); + if ($Slic3r::GUI::Settings->{_}{color_toolpaths_by} eq 'role') { + $self->{color_toolpaths_by_role}->Check(1); + } else { + $self->{color_toolpaths_by_extruder}->Check(1); + } } # Help menu @@ -800,10 +826,10 @@ sub select_view { } sub _append_menu_item { - my ($self, $menu, $string, $description, $cb, $id, $icon) = @_; + my ($self, $menu, $string, $description, $cb, $id, $icon, $kind) = @_; $id //= &Wx::NewId(); - my $item = $menu->Append($id, $string, $description); + my $item = $menu->Append($id, $string, $description, $kind); $self->_set_menu_item_icon($item, $icon); EVT_MENU($self, $id, $cb); diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index c72350def..efda7aedf 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -50,7 +50,7 @@ sub new { my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); $self->{config} = Slic3r::Config->new_from_defaults(qw( bed_shape complete_objects extruder_clearance_radius skirts skirt_distance brim_width - serial_port serial_speed octoprint_host octoprint_apikey + serial_port serial_speed octoprint_host octoprint_apikey filament_colour )); $self->{model} = Slic3r::Model->new; $self->{print} = Slic3r::Print->new; @@ -90,7 +90,7 @@ sub new { $menu->Destroy; }; my $on_instances_moved = sub { - $self->update; + $self->on_model_change; }; # Initialize 3D plater @@ -374,7 +374,7 @@ sub new { if ($self->{preview3D}) { $self->{preview3D}->set_bed_shape($self->{config}->bed_shape); } - $self->update; + $self->on_model_change; { my $presets; @@ -522,13 +522,12 @@ sub _on_select_preset { $Slic3r::GUI::Settings->{presets}{"filament_${_}"} = $choice->GetString($filament_presets[$_]) for 1 .. $#filament_presets; wxTheApp->save_settings; - return; + } else { + # call GetSelection() in scalar context as it's context-aware + $self->{on_select_preset}->($group, scalar $choice->GetSelection) + if $self->{on_select_preset}; } - # call GetSelection() in scalar context as it's context-aware - $self->{on_select_preset}->($group, scalar $choice->GetSelection) - if $self->{on_select_preset}; - # get new config and generate on_config_change() event for updating plater and other things $self->on_config_change($self->GetFrame->config); } @@ -735,7 +734,7 @@ sub load_model_objects { $self->make_thumbnail($obj_idx); } $self->arrange if $need_arrange; - $self->update; + $self->on_model_change; # zoom to objects $self->{canvas3D}->zoom_to_volumes @@ -745,8 +744,6 @@ sub load_model_objects { $self->{list}->Select($obj_idx[-1], 1); $self->object_list_changed; - $self->schedule_background_process; - return @obj_idx; } @@ -780,8 +777,7 @@ sub remove { $self->object_list_changed; $self->select_object(undef); - $self->update; - $self->schedule_background_process; + $self->on_model_change; } sub reset { @@ -800,7 +796,7 @@ sub reset { $self->object_list_changed; $self->select_object(undef); - $self->update; + $self->on_model_change; } sub increase { @@ -825,9 +821,8 @@ sub increase { if ($Slic3r::GUI::Settings->{_}{autocenter}) { $self->arrange; } else { - $self->update; + $self->on_model_change; } - $self->schedule_background_process; } sub decrease { @@ -852,8 +847,7 @@ sub decrease { $self->{list}->Select($obj_idx, 0); $self->{list}->Select($obj_idx, 1); } - $self->update; - $self->schedule_background_process; + $self->on_model_change; } sub set_number_of_copies { @@ -925,8 +919,7 @@ sub rotate { $self->{print}->add_model_object($model_object, $obj_idx); $self->selection_changed; # refresh info (size etc.) - $self->update; - $self->schedule_background_process; + $self->on_model_change; } sub mirror { @@ -953,8 +946,7 @@ sub mirror { $self->{print}->add_model_object($model_object, $obj_idx); $self->selection_changed; # refresh info (size etc.) - $self->update; - $self->schedule_background_process; + $self->on_model_change; } sub changescale { @@ -1035,8 +1027,7 @@ sub changescale { $self->{print}->add_model_object($model_object, $obj_idx); $self->selection_changed(1); # refresh info (size, volume etc.) - $self->update; - $self->schedule_background_process; + $self->on_model_change; } sub arrange { @@ -1049,7 +1040,7 @@ sub arrange { # ignore arrange failures on purpose: user has visual feedback and we don't need to warn him # when parts don't fit in print bed - $self->update(1); + $self->on_model_change(1); } sub split_object { @@ -1099,14 +1090,10 @@ sub split_object { sub schedule_background_process { my ($self) = @_; - $self->{processed} = 0; + warn 'schedule_background_process() is not supposed to be called when background processing is disabled' + if !$Slic3r::GUI::Settings->{_}{background_processing}; - if (!$Slic3r::GUI::Settings->{_}{background_processing}) { - my $sel = $self->{preview_notebook}->GetSelection; - if ($sel == $self->{preview3D_page_idx} || $sel == $self->{toolpaths2D_page_idx}) { - $self->{preview_notebook}->SetSelection(0); - } - } + $self->{processed} = 0; if (defined $self->{apply_config_timer}) { $self->{apply_config_timer}->Start(PROCESS_DELAY, 1); # 1 = one shot @@ -1118,10 +1105,6 @@ sub schedule_background_process { sub async_apply_config { my ($self) = @_; - # reset preview canvases - $self->{toolpaths2D}->reload_print if $self->{toolpaths2D}; - $self->{preview3D}->reload_print if $self->{preview3D}; - # pause process thread before applying new config # since we don't want to touch data that is being used by the threads $self->pause_background_process; @@ -1129,9 +1112,16 @@ sub async_apply_config { # apply new config my $invalidated = $self->{print}->apply_config($self->GetFrame->config); - return if !$Slic3r::GUI::Settings->{_}{background_processing}; + # reset preview canvases (invalidated contents will be hidden) + $self->{toolpaths2D}->reload_print if $self->{toolpaths2D}; + $self->{preview3D}->reload_print if $self->{preview3D}; if ($invalidated) { + if (!$Slic3r::GUI::Settings->{_}{background_processing}) { + $self->hide_preview; + return; + } + # kill current thread if any $self->stop_background_process; # remove the sliced statistics box because something changed. @@ -1629,30 +1619,45 @@ sub on_thumbnail_made { # this method gets called whenever print center is changed or the objects' bounding box changes # (i.e. when an object is added/removed/moved/rotated/scaled) -sub update { +sub on_model_change { my ($self, $force_autocenter) = @_; + my $running = $self->pause_background_process; + if ($Slic3r::GUI::Settings->{_}{autocenter} || $force_autocenter) { $self->{model}->center_instances_around_point($self->bed_centerf); } + $self->refresh_canvases; - my $running = $self->pause_background_process; my $invalidated = $self->{print}->reload_model_instances(); - # The mere fact that no steps were invalidated when reloading model instances - # doesn't mean that all steps were done: for example, validation might have - # failed upon previous instance move, so we have no running thread and no steps - # are invalidated on this move, thus we need to schedule a new run. - if ($invalidated || !$running) { - $self->schedule_background_process; + if ($Slic3r::GUI::Settings->{_}{background_processing}) { + if ($invalidated || !$running) { + # The mere fact that no steps were invalidated when reloading model instances + # doesn't mean that all steps were done: for example, validation might have + # failed upon previous instance move, so we have no running thread and no steps + # are invalidated on this move, thus we need to schedule a new run. + $self->schedule_background_process; + if ($self->{"right_sizer"}) { + $self->{"right_sizer"}->Hide($self->{"sliced_info_box"}); + $self->{"right_sizer"}->Layout; + } + } else { + $self->resume_background_process; + } } else { - $self->resume_background_process; + $self->hide_preview; } - if ($self->{"right_sizer"}) { - $self->{"right_sizer"}->Hide($self->{"sliced_info_box"}); - $self->{"right_sizer"}->Layout; +} + +sub hide_preview { + my ($self) = @_; + + my $sel = $self->{preview_notebook}->GetSelection; + if ($sel == $self->{preview3D_page_idx} || $sel == $self->{toolpaths2D_page_idx}) { + $self->{preview_notebook}->SetSelection(0); } - $self->refresh_canvases; + $self->{processed} = 0; } sub on_extruders_change { @@ -1701,6 +1706,7 @@ sub on_config_change { my $self = shift; my ($config) = @_; + # Apply changes to the plater-specific config options. foreach my $opt_key (@{$self->{config}->diff($config)}) { $self->{config}->set($opt_key, $config->get($opt_key)); if ($opt_key eq 'bed_shape') { @@ -1708,7 +1714,7 @@ sub on_config_change { $self->{canvas3D}->update_bed_size if $self->{canvas3D}; $self->{preview3D}->set_bed_shape($self->{config}->bed_shape) if $self->{preview3D}; - $self->update; + $self->on_model_change; } elsif ($opt_key eq 'serial_port') { if ($config->get('serial_port')) { $self->{btn_print}->Show; @@ -1723,8 +1729,12 @@ sub on_config_change { $self->{btn_send_gcode}->Hide; } $self->Layout; + } elsif (0 && $opt_key eq 'filament_colour') { + $self->{print}->config->set('filament_colour', $config->filament_colour); + $self->{preview3D}->reload_print if $self->{preview3D}; } } + if ($self->{"right_sizer"}) { $self->{"right_sizer"}->Hide($self->{"sliced_info_box"}); $self->{"right_sizer"}->Layout; @@ -1732,8 +1742,12 @@ sub on_config_change { return if !$self->GetFrame->is_loaded; - # (re)start timer - $self->schedule_background_process; + if ($Slic3r::GUI::Settings->{_}{background_processing}) { + # (re)start timer + $self->schedule_background_process; + } else { + $self->async_apply_config; + } } sub list_item_deselected { diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index c1d1cf57e..dddefee01 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -117,6 +117,16 @@ sub load_print { } if ($self->IsShown) { + # set colors + $self->canvas->color_toolpaths_by($Slic3r::GUI::Settings->{_}{color_toolpaths_by}); + if ($self->canvas->color_toolpaths_by eq 'extruder') { + my @filament_colors = map { s/^#//; [ map $_/255, (unpack 'C*', pack 'H*', $_), 255 ] } + @{$self->print->config->filament_colour}; + $self->canvas->colors->[$_] = $filament_colors[$_] for 0..$#filament_colors; + } else { + $self->canvas->colors([ $self->canvas->default_colors ]); + } + # load skirt and brim $self->canvas->load_print_toolpaths($self->print); diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 9a653e89d..3faad8317 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -462,11 +462,7 @@ sub process_layer { # extrude brim if (!$self->_brim_done) { - my $extr = $self->print->regions->[0]->config->perimeter_extruder-1; - if (my $o = first { $_->config->raft_layers > 0 } @{$self->objects}) { - $extr = $o->config->support_material_extruder-1; - } - $gcode .= $self->_gcodegen->set_extruder($extr); + $gcode .= $self->_gcodegen->set_extruder($self->print->brim_extruder-1); $self->_gcodegen->set_origin(Slic3r::Pointf->new(0,0)); $self->_gcodegen->avoid_crossing_perimeters->set_use_external_mp(1); $gcode .= $self->_gcodegen->extrude($_, 'brim', $object->config->support_material_speed) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index be6f24f38..807d58b45 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -187,6 +187,7 @@ Print::invalidate_state_by_config_options(const std::vector || *opt_key == "extrusion_multiplier" || *opt_key == "fan_always_on" || *opt_key == "fan_below_layer_time" + || *opt_key == "filament_colour" || *opt_key == "filament_diameter" || *opt_key == "first_layer_acceleration" || *opt_key == "first_layer_bed_temperature" @@ -348,6 +349,17 @@ Print::extruders() const return extruders; } +size_t +Print::brim_extruder() const +{ + size_t e = this->get_region(0)->config.perimeter_extruder; + for (const PrintObject* object : this->objects) { + if (object->config.raft_layers > 0) + e = object->config.support_material_extruder; + } + return e; +} + void Print::_simplify_slices(double distance) { diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index a5bc63def..b68ea6e35 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -214,6 +214,7 @@ class Print std::set object_extruders() const; std::set support_material_extruders() const; std::set extruders() const; + size_t brim_extruder() const; void _simplify_slices(double distance); double max_allowed_layer_height() const; bool has_support_material() const; diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 1bd25edb4..c4590a69e 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -224,6 +224,7 @@ _constant() RETVAL.push_back(*e); } %}; + int brim_extruder(); void clear_filament_stats() %code%{ THIS->filament_stats.clear(); From 6d0cb54cf2922c1a5e0d342462298ab1e54c854c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 17:01:19 +0100 Subject: [PATCH 77/96] A few more fixes to plater --- lib/Slic3r/GUI/Plater.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index efda7aedf..fe00e0260 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -528,8 +528,8 @@ sub _on_select_preset { if $self->{on_select_preset}; } - # get new config and generate on_config_change() event for updating plater and other things - $self->on_config_change($self->GetFrame->config); + # generate on_config_change() event for updating plater and other things + $self->on_config_change(); } sub GetFrame { @@ -1704,7 +1704,12 @@ sub on_extruders_change { sub on_config_change { my $self = shift; - my ($config) = @_; + + my $config = $self->GetFrame->config; + + if ($Slic3r::GUI::autosave) { + $config->save($Slic3r::GUI::autosave); + } # Apply changes to the plater-specific config options. foreach my $opt_key (@{$self->{config}->diff($config)}) { @@ -1729,9 +1734,6 @@ sub on_config_change { $self->{btn_send_gcode}->Hide; } $self->Layout; - } elsif (0 && $opt_key eq 'filament_colour') { - $self->{print}->config->set('filament_colour', $config->filament_colour); - $self->{preview3D}->reload_print if $self->{preview3D}; } } @@ -1839,7 +1841,7 @@ sub object_settings_dialog { if ($dlg->PartsChanged || $dlg->PartSettingsChanged) { $self->stop_background_process; $self->{print}->reload_object($obj_idx); - $self->schedule_background_process; + $self->on_model_change; } else { $self->resume_background_process; } From d7efd51beb36894ff0a58048c36a80b860fe0f75 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 20 Mar 2017 12:03:53 -0500 Subject: [PATCH 78/96] Quote the paths in osx startup script. --- package/osx/startup_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/osx/startup_script.sh b/package/osx/startup_script.sh index b98fa5bdc..4f665ac64 100644 --- a/package/osx/startup_script.sh +++ b/package/osx/startup_script.sh @@ -1,4 +1,4 @@ #!/bin/bash DIR=$(dirname "$0") -$DIR/perl-local -I$DIR/local-lib/lib/perl5 $DIR/slic3r.pl $@ +"$DIR/perl-local" -I"$DIR/local-lib/lib/perl5" "$DIR/slic3r.pl" $@ From 0c4e16589bee9878caf4cdfa8eac4e039dee02cc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 18:51:15 +0100 Subject: [PATCH 79/96] Prevent ExtUtils::CppGuess from linking to libstdc++ on OS X --- xs/Build.PL | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xs/Build.PL b/xs/Build.PL index 87ba0c1ef..619cc879f 100644 --- a/xs/Build.PL +++ b/xs/Build.PL @@ -39,6 +39,19 @@ if ($^O eq 'darwin') { # that prevents this from happening, not needed with newer Boost versions. # See here for more details: https://svn.boost.org/trac/boost/ticket/7671 push @cflags, qw(-DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE); + + # ExtUtils::CppGuess has a hard-coded -lstdc++, so we filter it out + { + no strict 'refs'; + no warnings 'redefine'; + my $func = "ExtUtils::CppGuess::_get_lflags"; + my $orig = *$func{CODE}; + *{$func} = sub { + my $lflags = $orig->(@_); + $lflags =~ s/\s*-lstdc\+\+//; + return $lflags; + }; + } } if ($mswin) { # In case windows.h is included, we don't want the min / max macros to be active. From a69e4e39c9fa2ab62ea0dbe80f66c8d847b83b67 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 19:28:08 +0100 Subject: [PATCH 80/96] Bugfix (untested): prevent cursor to go to the beginning while typing in a slider textctrl. #3779 --- lib/Slic3r/GUI/OptionsGroup/Field.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/OptionsGroup/Field.pm b/lib/Slic3r/GUI/OptionsGroup/Field.pm index d2cf76ce6..2bf3701d9 100644 --- a/lib/Slic3r/GUI/OptionsGroup/Field.pm +++ b/lib/Slic3r/GUI/OptionsGroup/Field.pm @@ -573,7 +573,8 @@ sub get_value { sub _update_textctrl { my ($self) = @_; - $self->textctrl->SetLabel($self->get_value); + $self->textctrl->ChangeValue($self->get_value); + $self->textctrl->SetInsertionPointEnd; } sub enable { From 9ad1360e445cd3043c4dc30ccad64b82b914f952 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 22:22:38 +0100 Subject: [PATCH 81/96] Bugfix: when the Voronoi diagram contained very large coordinates we need to check whether they are greater than our allowed range and consider the Voronoi edges infinite in those cases, in order to prevent overflows. #3776 --- xs/src/libslic3r/ClipperUtils.hpp | 3 ++- xs/src/libslic3r/ExPolygon.cpp | 8 ++++++++ xs/src/libslic3r/ExPolygon.hpp | 3 +++ xs/src/libslic3r/Geometry.cpp | 10 +++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/ClipperUtils.hpp b/xs/src/libslic3r/ClipperUtils.hpp index 9e4e5e89a..f76661215 100644 --- a/xs/src/libslic3r/ClipperUtils.hpp +++ b/xs/src/libslic3r/ClipperUtils.hpp @@ -19,7 +19,8 @@ namespace Slic3r { // How about 2^17=131072? // By the way, is the scalling needed at all? Cura runs all the computation with a fixed point precision of 1um, while Slic3r scales to 1nm, // further scaling by 10e5 brings us to -#define CLIPPER_OFFSET_SCALE 100000.0 +static const float CLIPPER_OFFSET_SCALE = 100000.0; +static const coord_t MAX_COORD = ClipperLib::hiRange / CLIPPER_OFFSET_SCALE; //----------------------------------------------------------- // legacy code from Clipper documentation diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index ec02acc35..93fbba467 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -514,4 +514,12 @@ ExPolygon::dump_perl() const return ret.str(); } +std::ostream& +operator <<(std::ostream &s, const ExPolygons &expolygons) +{ + for (const ExPolygon &e : expolygons) + s << e.dump_perl() << std::endl; + return s; +} + } diff --git a/xs/src/libslic3r/ExPolygon.hpp b/xs/src/libslic3r/ExPolygon.hpp index 63cc560cd..404a4385e 100644 --- a/xs/src/libslic3r/ExPolygon.hpp +++ b/xs/src/libslic3r/ExPolygon.hpp @@ -4,6 +4,7 @@ #include "libslic3r.h" #include "Polygon.hpp" #include "Polyline.hpp" +#include #include namespace Slic3r { @@ -62,6 +63,8 @@ operator+(ExPolygons src1, const ExPolygons &src2) { return src1; }; +std::ostream& operator <<(std::ostream &s, const ExPolygons &expolygons); + } // start Boost diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index 0cc9a575c..ccd645e2f 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -7,13 +7,14 @@ #include #include #include +#include #include #include #include #include #include #include - +#define SLIC3R_DEBUG #ifdef SLIC3R_DEBUG #include "SVG.hpp" #endif @@ -609,6 +610,13 @@ MedialAxis::process_edge_neighbors(const VD::edge_type* edge, ThickPolyline* pol bool MedialAxis::validate_edge(const VD::edge_type* edge) { + // prevent overflows and detect almost-infinite edges + if (std::abs(edge->vertex0()->x()) > (double)MAX_COORD + || std::abs(edge->vertex0()->y()) > (double)MAX_COORD + || std::abs(edge->vertex1()->x()) > (double)MAX_COORD + || std::abs(edge->vertex1()->y()) > (double)MAX_COORD) + return false; + // construct the line representing this edge of the Voronoi diagram const Line line( Point( edge->vertex0()->x(), edge->vertex0()->y() ), From a301e6afa4154900a55f70f147639905d16394c2 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 22:37:42 +0100 Subject: [PATCH 82/96] Removed two extra lines left in previous commit --- xs/src/libslic3r/Geometry.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index ccd645e2f..b8584000f 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -7,14 +7,13 @@ #include #include #include -#include #include #include #include #include #include #include -#define SLIC3R_DEBUG + #ifdef SLIC3R_DEBUG #include "SVG.hpp" #endif From 61c8359995e785a638d2f39390c2998a889b4a93 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Mar 2017 23:02:47 +0100 Subject: [PATCH 83/96] Ignore solid_infill_below_area when fill_density is already 100%. #3380 --- xs/src/libslic3r/LayerRegion.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xs/src/libslic3r/LayerRegion.cpp b/xs/src/libslic3r/LayerRegion.cpp index b7d9058fe..1baaa0bef 100644 --- a/xs/src/libslic3r/LayerRegion.cpp +++ b/xs/src/libslic3r/LayerRegion.cpp @@ -231,12 +231,13 @@ LayerRegion::prepare_fill_surfaces() } // turn too small internal regions into solid regions according to the user setting - if (this->region()->config.fill_density.value > 0) { + const float &fill_density = this->region()->config.fill_density; + if (fill_density > 0 && fill_density < 100) { // scaling an area requires two calls! - double min_area = scale_(scale_(this->region()->config.solid_infill_below_area.value)); - for (Surfaces::iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface) { - if (surface->surface_type == stInternal && surface->area() <= min_area) - surface->surface_type = stInternalSolid; + const double min_area = scale_(scale_(this->region()->config.solid_infill_below_area.value)); + for (Surface &surface : this->fill_surfaces.surfaces) { + if (surface.surface_type == stInternal && surface.area() <= min_area) + surface.surface_type = stInternalSolid; } } } From ecc171eca6971922441bf0d713ee400582373e47 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 21 Mar 2017 14:40:32 +0100 Subject: [PATCH 84/96] Bugfix: use_relative_e_distances and spiral vase were broken again after the port. #3784 --- xs/src/libslic3r/GCodeReader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xs/src/libslic3r/GCodeReader.cpp b/xs/src/libslic3r/GCodeReader.cpp index fcaaea9be..1a0742864 100644 --- a/xs/src/libslic3r/GCodeReader.cpp +++ b/xs/src/libslic3r/GCodeReader.cpp @@ -56,6 +56,9 @@ GCodeReader::parse(const std::string &gcode, callback_t callback) } } + if (gline.has('E') && this->_config.use_relative_e_distances) + this->E = 0; + if (callback) callback(*this, gline); // update coordinates From 8250839fd5200bad9b180c056055acf515b0ad6f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 21 Mar 2017 16:40:31 +0100 Subject: [PATCH 85/96] constexpr party --- xs/src/clipper.hpp | 2 +- xs/src/libslic3r/ClipperUtils.hpp | 4 +- xs/src/libslic3r/Flow.hpp | 4 +- xs/src/libslic3r/GCode.cpp | 4 +- xs/src/libslic3r/GCodeSender.cpp | 4 +- xs/src/libslic3r/MotionPlanner.hpp | 6 +-- xs/src/libslic3r/SupportMaterial.hpp | 2 +- xs/src/libslic3r/libslic3r.h | 56 ++++++++++++++-------------- 8 files changed, 42 insertions(+), 40 deletions(-) diff --git a/xs/src/clipper.hpp b/xs/src/clipper.hpp index df1f8137d..66876905c 100755 --- a/xs/src/clipper.hpp +++ b/xs/src/clipper.hpp @@ -76,7 +76,7 @@ enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative }; #else typedef signed long long cInt; static cInt const loRange = 0x3FFFFFFF; - static cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL; + constexpr cInt hiRange = 0x3FFFFFFFFFFFFFFFLL; typedef signed long long long64; //used by Int128 class typedef unsigned long long ulong64; diff --git a/xs/src/libslic3r/ClipperUtils.hpp b/xs/src/libslic3r/ClipperUtils.hpp index f76661215..ddd551ca2 100644 --- a/xs/src/libslic3r/ClipperUtils.hpp +++ b/xs/src/libslic3r/ClipperUtils.hpp @@ -19,8 +19,8 @@ namespace Slic3r { // How about 2^17=131072? // By the way, is the scalling needed at all? Cura runs all the computation with a fixed point precision of 1um, while Slic3r scales to 1nm, // further scaling by 10e5 brings us to -static const float CLIPPER_OFFSET_SCALE = 100000.0; -static const coord_t MAX_COORD = ClipperLib::hiRange / CLIPPER_OFFSET_SCALE; +constexpr float CLIPPER_OFFSET_SCALE = 100000.0; +constexpr auto MAX_COORD = ClipperLib::hiRange / CLIPPER_OFFSET_SCALE; //----------------------------------------------------------- // legacy code from Clipper documentation diff --git a/xs/src/libslic3r/Flow.hpp b/xs/src/libslic3r/Flow.hpp index 2f041d03c..fdfcac695 100644 --- a/xs/src/libslic3r/Flow.hpp +++ b/xs/src/libslic3r/Flow.hpp @@ -7,8 +7,8 @@ namespace Slic3r { -#define BRIDGE_EXTRA_SPACING 0.05 -#define OVERLAP_FACTOR 1.0 +constexpr auto BRIDGE_EXTRA_SPACING = 0.05; +constexpr auto OVERLAP_FACTOR = 1.0; enum FlowRole { frExternalPerimeter, diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 39af871b2..f6ae8f75a 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -453,8 +453,8 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) paths.front().polyline.points[0], paths.front().polyline.points[1] ); - double distance = std::min( - scale_(EXTRUDER_CONFIG(nozzle_diameter)), + const double distance = std::min( + (double)scale_(EXTRUDER_CONFIG(nozzle_diameter)), first_segment.length() ); Point point = first_segment.point_at(distance); diff --git a/xs/src/libslic3r/GCodeSender.cpp b/xs/src/libslic3r/GCodeSender.cpp index 5fc33d9c9..c1568790e 100644 --- a/xs/src/libslic3r/GCodeSender.cpp +++ b/xs/src/libslic3r/GCodeSender.cpp @@ -26,10 +26,10 @@ std::fstream fs; #endif -#define KEEP_SENT 20 - namespace Slic3r { +constexpr auto KEEP_SENT = 20; + namespace asio = boost::asio; GCodeSender::GCodeSender() diff --git a/xs/src/libslic3r/MotionPlanner.hpp b/xs/src/libslic3r/MotionPlanner.hpp index 1fbdb4123..80d61213e 100644 --- a/xs/src/libslic3r/MotionPlanner.hpp +++ b/xs/src/libslic3r/MotionPlanner.hpp @@ -9,11 +9,11 @@ #include #include -#define MP_INNER_MARGIN scale_(1.0) -#define MP_OUTER_MARGIN scale_(2.0) - namespace Slic3r { +constexpr coord_t MP_INNER_MARGIN = scale_(1.0); +constexpr coord_t MP_OUTER_MARGIN = scale_(2.0); + class MotionPlanner; class MotionPlannerEnv diff --git a/xs/src/libslic3r/SupportMaterial.hpp b/xs/src/libslic3r/SupportMaterial.hpp index edea22695..03703aa40 100644 --- a/xs/src/libslic3r/SupportMaterial.hpp +++ b/xs/src/libslic3r/SupportMaterial.hpp @@ -4,7 +4,7 @@ namespace Slic3r { // how much we extend support around the actual contact area -#define SUPPORT_MATERIAL_MARGIN 1.5 +constexpr coordf_t SUPPORT_MATERIAL_MARGIN = 1.5; } diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h index 6789d58ff..50b4241de 100644 --- a/xs/src/libslic3r/libslic3r.h +++ b/xs/src/libslic3r/libslic3r.h @@ -10,33 +10,6 @@ #include #include -#define SLIC3R_VERSION "1.3.0-dev" - -//FIXME This epsilon value is used for many non-related purposes: -// For a threshold of a squared Euclidean distance, -// for a trheshold in a difference of radians, -// for a threshold of a cross product of two non-normalized vectors etc. -#define EPSILON 1e-4 -// Scaling factor for a conversion from coord_t to coordf_t: 10e-6 -// This scaling generates a following fixed point representation with for a 32bit integer: -// 0..4294mm with 1nm resolution -#define SCALING_FACTOR 0.000001 -// RESOLUTION, SCALED_RESOLUTION: Used as an error threshold for a Douglas-Peucker polyline simplification algorithm. -#define RESOLUTION 0.0125 -#define SCALED_RESOLUTION (RESOLUTION / SCALING_FACTOR) -#define PI 3.141592653589793238 -// When extruding a closed loop, the loop is interrupted and shortened a bit to reduce the seam. -#define LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER 0.15 -// Maximum perimeter length for the loop to apply the small perimeter speed. -#define SMALL_PERIMETER_LENGTH (6.5 / SCALING_FACTOR) * 2 * PI -#define INSET_OVERLAP_TOLERANCE 0.4 -#define EXTERNAL_INFILL_MARGIN 3 -#define scale_(val) ((val) / SCALING_FACTOR) -#define unscale(val) ((val) * SCALING_FACTOR) -#define SCALED_EPSILON scale_(EPSILON) -typedef long coord_t; -typedef double coordf_t; - /* Implementation of CONFESS("foo"): */ #ifdef _MSC_VER #define CONFESS(...) confess_at(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) @@ -61,6 +34,35 @@ void confess_at(const char *file, int line, const char *func, const char *pat, . namespace Slic3r { +constexpr auto SLIC3R_VERSION = "1.3.0-dev"; + +typedef long coord_t; +typedef double coordf_t; + +// Scaling factor for a conversion from coord_t to coordf_t: 10e-6 +// This scaling generates a following fixed point representation with for a 32bit integer: +// 0..4294mm with 1nm resolution +constexpr auto SCALING_FACTOR = 0.000001; +inline constexpr coord_t scale_(const coordf_t &val) { return val / SCALING_FACTOR; } +inline constexpr coordf_t unscale(const coord_t &val) { return val * SCALING_FACTOR; } + +//FIXME This epsilon value is used for many non-related purposes: +// For a threshold of a squared Euclidean distance, +// for a trheshold in a difference of radians, +// for a threshold of a cross product of two non-normalized vectors etc. +constexpr auto EPSILON = 1e-4; +constexpr auto SCALED_EPSILON = scale_(EPSILON); +// RESOLUTION, SCALED_RESOLUTION: Used as an error threshold for a Douglas-Peucker polyline simplification algorithm. +constexpr auto RESOLUTION = 0.0125; +constexpr auto SCALED_RESOLUTION = scale_(RESOLUTION); +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; + enum Axis { X=0, Y, Z }; template From ddad7ce25f59b34552ff2b119597366655be3754 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 21 Mar 2017 16:48:04 +0100 Subject: [PATCH 86/96] One more fix for slider. #3779 --- lib/Slic3r/GUI/OptionsGroup/Field.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/OptionsGroup/Field.pm b/lib/Slic3r/GUI/OptionsGroup/Field.pm index 2bf3701d9..920d4cec1 100644 --- a/lib/Slic3r/GUI/OptionsGroup/Field.pm +++ b/lib/Slic3r/GUI/OptionsGroup/Field.pm @@ -548,11 +548,16 @@ sub BUILD { EVT_TEXT($self->parent, $textctrl, sub { my $value = $textctrl->GetValue; if ($value =~ /^-?\d+(\.\d*)?$/) { - $self->set_value($value); + # Update the slider without re-updating the text field being modified. + $self->disable_change_event(1); + $self->slider->SetValue($value*$self->scale); + $self->disable_change_event(0); + $self->_on_change($self->option->opt_id); } }); EVT_KILL_FOCUS($textctrl, sub { + $self->_update_textctrl; $self->_on_kill_focus($self->option->opt_id, @_); }); } @@ -573,6 +578,7 @@ sub get_value { sub _update_textctrl { my ($self) = @_; + $self->textctrl->ChangeValue($self->get_value); $self->textctrl->SetInsertionPointEnd; } From 856065537208bdb8a85a148c0946f58cbce3e49b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 21 Mar 2017 17:33:49 +0100 Subject: [PATCH 87/96] Only reload the selected object and not all the objects of the input file. #3786 --- lib/Slic3r/GUI/Plater.pm | 29 +++++++++++++++++++++++------ xs/src/libslic3r/Model.cpp | 14 ++++++-------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index fe00e0260..b7393c0af 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -632,7 +632,7 @@ sub add_tin { sub load_file { my $self = shift; - my ($input_file) = @_; + my ($input_file, $obj_idx) = @_; $Slic3r::GUI::Settings->{recent}{skein_directory} = dirname($input_file); wxTheApp->save_settings; @@ -657,7 +657,19 @@ sub load_file { $model->convert_multipart_object; } } - @obj_idx = $self->load_model_objects(@{$model->objects}); + + if (defined $obj_idx) { + return () if $obj_idx >= $model->objects_count; + @obj_idx = $self->load_model_objects($model->get_object($obj_idx)); + } else { + @obj_idx = $self->load_model_objects(@{$model->objects}); + } + + my $i = 0; + foreach my $obj_idx (@obj_idx) { + $self->{objects}[$obj_idx]->input_file($input_file); + $self->{objects}[$obj_idx]->input_file_obj_idx($i++); + } $self->statusbar->SetStatusText("Loaded " . basename($input_file)); } @@ -1488,13 +1500,14 @@ sub reload_from_disk { my ($obj_idx, $object) = $self->selected_object; return if !defined $obj_idx; - my $model_object = $self->{model}->objects->[$obj_idx]; - return if !$model_object->input_file - || !-e $model_object->input_file; + return if !$object->input_file + || !-e $object->input_file; - my @new_obj_idx = $self->load_file($model_object->input_file); + # Only reload the selected object and not all objects from the input file. + my @new_obj_idx = $self->load_file($object->input_file, $object->input_file_obj_idx); return if !@new_obj_idx; + my $model_object = $self->{model}->objects->[$obj_idx]; foreach my $new_obj_idx (@new_obj_idx) { my $o = $self->{model}->objects->[$new_obj_idx]; $o->clear_instances; @@ -1509,6 +1522,8 @@ sub reload_from_disk { $self->remove($obj_idx); + # TODO: refresh object list which contains wrong count and scale + # Trigger thumbnail generation again, because the remove() method altered # object indexes before background thumbnail generation called its completion # event, so the on_thumbnail_made callback is called with the wrong $obj_idx. @@ -2127,6 +2142,8 @@ use List::Util qw(first); use Slic3r::Geometry qw(X Y Z MIN MAX deg2rad); has 'name' => (is => 'rw', required => 1); +has 'input_file' => (is => 'rw'); +has 'input_file_obj_idx' => (is => 'rw'); has 'thumbnail' => (is => 'rw'); # ExPolygon::Collection in scaled model units with no transforms has 'transformed_thumbnail' => (is => 'rw'); has 'instance_thumbnails' => (is => 'ro', default => sub { [] }); # array of ExPolygon::Collection objects, each one representing the actual placed thumbnail of each instance in pixel units diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index ca9c0b227..9182cf56b 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -92,9 +92,8 @@ Model::delete_object(size_t idx) void Model::clear_objects() { - // int instead of size_t because it can be -1 when vector is empty - for (int i = this->objects.size()-1; i >= 0; --i) - this->delete_object(i); + while (!this->objects.empty()) + this->delete_object(0); } void @@ -467,9 +466,8 @@ ModelObject::delete_volume(size_t idx) void ModelObject::clear_volumes() { - // int instead of size_t because it can be -1 when vector is empty - for (int i = this->volumes.size()-1; i >= 0; --i) - this->delete_volume(i); + while (!this->volumes.empty()) + this->delete_volume(0); } ModelInstance* @@ -508,8 +506,8 @@ ModelObject::delete_last_instance() void ModelObject::clear_instances() { - for (size_t i = 0; i < this->instances.size(); ++i) - this->delete_instance(i); + while (!this->instances.empty()) + this->delete_last_instance(); } // this returns the bounding box of the *transformed* instances From 4c14c656f5c9adf712dfbcea0dc1b7c044131c37 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 21 Mar 2017 17:38:39 +0100 Subject: [PATCH 88/96] Updated MANIFEST --- xs/MANIFEST | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xs/MANIFEST b/xs/MANIFEST index a2ffbba5a..61a97afed 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -68,6 +68,8 @@ src/libslic3r/GCode/CoolingBuffer.cpp src/libslic3r/GCode/CoolingBuffer.hpp src/libslic3r/GCode/SpiralVase.cpp src/libslic3r/GCode/SpiralVase.hpp +src/libslic3r/GCodeReader.cpp +src/libslic3r/GCodeReader.hpp src/libslic3r/GCodeSender.cpp src/libslic3r/GCodeSender.hpp src/libslic3r/GCodeWriter.cpp From 488cc02f531d63e8d87a3a572853a391ae8a7647 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Mar 2017 12:49:25 +0100 Subject: [PATCH 89/96] Try to fix OctoPrint issues. #3789 --- lib/Slic3r/GUI/Plater.pm | 87 +++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index b7393c0af..d7bb3195d 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -256,43 +256,10 @@ sub new { EVT_LEFT_UP($self->{btn_send_gcode}, sub { my (undef, $e) = @_; - my $filename = basename($self->{print}->output_filepath($main::opt{output} // '')); - - if (!$e->AltDown) { - # When the alt key is pressed, bypass the dialog. - my $dlg = Slic3r::GUI::Plater::OctoPrintSpoolDialog->new($self, $filename); - return unless $dlg->ShowModal == wxID_OK; - $filename = $dlg->{filename}; - } - - if (!$Slic3r::GUI::Settings->{octoprint}{overwrite}) { - my $progress = Wx::ProgressDialog->new('Querying OctoPrint…', - "Checking whether file already exists…", 100, $self, 0); - $progress->Pulse; - - my $ua = LWP::UserAgent->new; - $ua->timeout(5); - my $res = $ua->get("http://" . $self->{config}->octoprint_host . "/api/files/local"); - $progress->Destroy; - if ($res->is_success) { - if ($res->decoded_content =~ /"name":\s*"\Q$filename\E"/) { - my $dialog = Wx::MessageDialog->new($self, - "It looks like a file with the same name already exists in the server. " - . "Shall I overwrite it?", - 'OctoPrint', wxICON_WARNING | wxYES | wxNO); - if ($dialog->ShowModal() == wxID_NO) { - return; - } - } - } else { - my $message = "Error while connecting to the OctoPrint server: " . $res->status_line; - Slic3r::GUI::show_error($self, $message); - return; - } - } - - $self->{send_gcode_file_print} = $Slic3r::GUI::Settings->{octoprint}{start}; - $self->{send_gcode_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir() . "/" . $filename); + my $alt = $e->AltDown; + wxTheApp->CallAfter(sub { + $self->prepare_send($alt); + }); }); EVT_BUTTON($self, $self->{btn_export_stl}, \&export_stl); @@ -1452,6 +1419,52 @@ sub do_print { $self->GetFrame->select_tab(1); } +sub prepare_send { + my ($self, $skip_dialog) = @_; + + return if !$self->{btn_send_gcode}->IsEnabled; + my $filename = basename($self->{print}->output_filepath($main::opt{output} // '')); + + if (!$skip_dialog) { + # When the alt key is pressed, bypass the dialog. + my $dlg = Slic3r::GUI::Plater::OctoPrintSpoolDialog->new($self, $filename); + return unless $dlg->ShowModal == wxID_OK; + $filename = $dlg->{filename}; + } + + if (!$Slic3r::GUI::Settings->{octoprint}{overwrite}) { + my $progress = Wx::ProgressDialog->new('Querying OctoPrint…', + "Checking whether file already exists…", 100, $self, 0); + $progress->Pulse; + + my $ua = LWP::UserAgent->new; + $ua->timeout(5); + my $res = $ua->get( + "http://" . $self->{config}->octoprint_host . "/api/files/local", + 'X-Api-Key' => $self->{config}->octoprint_apikey, + ); + $progress->Destroy; + if ($res->is_success) { + if ($res->decoded_content =~ /"name":\s*"\Q$filename\E"/) { + my $dialog = Wx::MessageDialog->new($self, + "It looks like a file with the same name already exists in the server. " + . "Shall I overwrite it?", + 'OctoPrint', wxICON_WARNING | wxYES | wxNO); + if ($dialog->ShowModal() == wxID_NO) { + return; + } + } + } else { + my $message = "Error while connecting to the OctoPrint server: " . $res->status_line; + Slic3r::GUI::show_error($self, $message); + return; + } + } + + $self->{send_gcode_file_print} = $Slic3r::GUI::Settings->{octoprint}{start}; + $self->{send_gcode_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir() . "/" . $filename); +} + sub send_gcode { my ($self) = @_; From 0de3a72eb40a408d64ecfb5fa7ca461718fc4ba8 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Mar 2017 12:59:05 +0100 Subject: [PATCH 90/96] Bugfix: canceling the "Set Copies" dialog didn't work. #3787 --- lib/Slic3r/GUI/Plater.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index d7bb3195d..30745ab80 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -840,6 +840,7 @@ sub set_number_of_copies { # prompt user my $copies = Wx::GetNumberFromUser("", "Enter the number of copies of the selected object:", "Copies", $model_object->instances_count, 0, 1000, $self); + return if $copies == -1; my $diff = $copies - $model_object->instances_count; if ($diff == 0) { # no variation From 84a5075fceccddd7a24fda88200a2f2e2f620b98 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Mar 2017 13:57:18 +0100 Subject: [PATCH 91/96] Bugfix: excessive copies were created when converting a multi-object AMF file into a multi-part object. #3788 --- lib/Slic3r/Model.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 99c69cd4a..0b6cefd75 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -74,7 +74,7 @@ sub convert_multipart_object { my $volume = $object->add_volume($v); $volume->set_name($v->object->name); } - $object->add_instance($_) for map @{$_->instances}, @objects; + $object->add_instance($_) for @{$objects[0]->instances}; $self->delete_object($_) for reverse 0..($self->objects_count-2); } From bd2117d3462965d7c508b646b3d03235024a36f1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Mar 2017 14:10:41 +0100 Subject: [PATCH 92/96] Align objects imported from AMF to ground. #3785 --- lib/Slic3r/GUI/Plater.pm | 3 +++ xs/src/libslic3r/Model.cpp | 14 ++++++++++++++ xs/src/libslic3r/Model.hpp | 1 + xs/xsp/Model.xsp | 1 + 4 files changed, 19 insertions(+) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 30745ab80..d43f1cf52 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -671,6 +671,9 @@ sub load_model_objects { # add a default instance and center object around origin $o->center_around_origin; # also aligns object to Z = 0 $o->add_instance(offset => $bed_centerf); + } else { + # if object has defined positions we still need to ensure it's aligned to Z = 0 + $o->align_to_ground; } { diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 9182cf56b..b1694190e 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -597,6 +597,20 @@ ModelObject::instance_bounding_box(size_t instance_idx) const return bb; } +void +ModelObject::align_to_ground() +{ + // calculate the displacements needed to + // center this object around the origin + BoundingBoxf3 bb; + for (const ModelVolume* v : this->volumes) + if (!v->modifier) + bb.merge(v->mesh.bounding_box()); + + this->translate(0, 0, -bb.min.z); + this->origin_translation.translate(0, 0, -bb.min.z); +} + void ModelObject::center_around_origin() { diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 9c8e0d1e2..1b6c6d6c2 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -149,6 +149,7 @@ class ModelObject TriangleMesh raw_mesh() const; BoundingBoxf3 raw_bounding_box() const; BoundingBoxf3 instance_bounding_box(size_t instance_idx) const; + void align_to_ground(); void center_around_origin(); void translate(const Vectorf3 &vector); void translate(coordf_t x, coordf_t y, coordf_t z); diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index c5c700606..53f6cc8f3 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -207,6 +207,7 @@ ModelMaterial::attributes() bool needed_repair() const; int materials_count() const; int facets_count(); + void align_to_ground(); void center_around_origin(); void translate(double x, double y, double z); void scale_xyz(Pointf3* versor) From 3ee628c29f1168f56896555f09a1f29dc9b53ac6 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Mar 2017 14:23:28 +0100 Subject: [PATCH 93/96] Ported couple Model methods to C++ --- lib/Slic3r/Model.pm | 27 --------------------------- xs/src/libslic3r/Model.cpp | 38 ++++++++++++++++++++++++++++++++++++++ xs/src/libslic3r/Model.hpp | 2 ++ xs/xsp/Model.xsp | 2 ++ 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 0b6cefd75..cba64323a 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -52,33 +52,6 @@ sub set_material { return $material; } -sub looks_like_multipart_object { - my ($self) = @_; - - return 0 if $self->objects_count == 1; - return 0 if any { $_->volumes_count > 1 } @{$self->objects}; - return 0 if any { @{$_->config->get_keys} > 1 } @{$self->objects}; - - my %heights = map { $_ => 1 } map $_->mesh->bounding_box->z_min, map @{$_->volumes}, @{$self->objects}; - return scalar(keys %heights) > 1; -} - -sub convert_multipart_object { - my ($self) = @_; - - my @objects = @{$self->objects}; - my $object = $self->add_object( - input_file => $objects[0]->input_file, - ); - foreach my $v (map @{$_->volumes}, @objects) { - my $volume = $object->add_volume($v); - $volume->set_name($v->object->name); - } - $object->add_instance($_) for @{$objects[0]->instances}; - - $self->delete_object($_) for reverse 0..($self->objects_count-2); -} - # Extends C++ class Slic3r::ModelMaterial package Slic3r::Model::Material; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index b1694190e..5243799ca 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -2,6 +2,7 @@ #include "Geometry.hpp" #include "IO.hpp" #include +#include #include #include @@ -372,6 +373,43 @@ Model::print_info() const (*o)->print_info(); } +bool +Model::looks_like_multipart_object() const +{ + if (this->objects.size() == 1) return false; + for (const ModelObject* o : this->objects) { + if (o->volumes.size() > 1) return false; + if (o->config.keys().size() > 1) return false; + } + + std::set heights; + for (const ModelObject* o : this->objects) + for (const ModelVolume* v : o->volumes) + heights.insert(v->mesh.bounding_box().min.z); + return heights.size() > 1; +} + +void +Model::convert_multipart_object() +{ + if (this->objects.empty()) return; + + ModelObject* object = this->add_object(); + object->input_file = this->objects.front()->input_file; + + for (const ModelObject* o : this->objects) { + for (const ModelVolume* v : o->volumes) { + ModelVolume* v2 = object->add_volume(*v); + v2->name = o->name; + } + } + for (const ModelInstance* i : this->objects.front()->instances) + object->add_instance(*i); + + while (this->objects.size() > 1) + this->delete_object(0); +} + ModelMaterial::ModelMaterial(Model *model) : model(model) {} ModelMaterial::ModelMaterial(Model *model, const ModelMaterial &other) : attributes(other.attributes), config(other.config), model(model) diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 1b6c6d6c2..36571ff5d 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -74,6 +74,8 @@ class Model void duplicate_objects(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL); void duplicate_objects_grid(size_t x, size_t y, coordf_t dist); void print_info() const; + bool looks_like_multipart_object() const; + void convert_multipart_object(); }; // Material, which may be shared across multiple ModelObjects of a single Model. diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 53f6cc8f3..cb415ad14 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -95,6 +95,8 @@ void duplicate_objects(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL); void duplicate_objects_grid(unsigned int x, unsigned int y, double dist); void print_info(); + bool looks_like_multipart_object(); + void convert_multipart_object(); void repair(); }; From b755e2424f30af3b856593102ecc3d0b7900c0dc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Mar 2017 14:26:56 +0100 Subject: [PATCH 94/96] Removed warning --- xs/t/15_config.t | 1 + 1 file changed, 1 insertion(+) diff --git a/xs/t/15_config.t b/xs/t/15_config.t index 214baad9f..f6efc8a5d 100644 --- a/xs/t/15_config.t +++ b/xs/t/15_config.t @@ -286,6 +286,7 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintCo is_deeply $config->get('retract_speed'), [0.4, 0.5], 'read_cli(): floats array'; } { + no warnings 'qw'; my $config = $parse->(qw(--extruder-offset 0,0 --extruder-offset 10x5)); is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[0,0], [10,5]], 'read_cli(): points array'; From e359cd0a4a2254526b9f3d08ff5773122731dff1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 23 Mar 2017 14:46:45 +0100 Subject: [PATCH 95/96] Support Mac Retina displays --- package/osx/plist.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package/osx/plist.sh b/package/osx/plist.sh index 898ae3be2..38e03edbc 100644 --- a/package/osx/plist.sh +++ b/package/osx/plist.sh @@ -91,6 +91,8 @@ cat << EOF >> $plistfile LSMinimumSystemVersion 10.7 + NSPrincipalClass + NSApplication EOF From b1372d43659757b1a60d14dc5ba4819dc4124755 Mon Sep 17 00:00:00 2001 From: Florens Wasserfall Date: Thu, 23 Mar 2017 14:53:28 +0100 Subject: [PATCH 96/96] Ported most of slice() to C++ --- lib/Slic3r/Print/Object.pm | 263 +------------------------ xs/src/libslic3r/Print.hpp | 3 + xs/src/libslic3r/PrintObject.cpp | 240 ++++++++++++++++++++++ xs/src/libslic3r/Surface.hpp | 87 ++++++++ xs/src/libslic3r/SurfaceCollection.hpp | 10 + xs/xsp/Print.xsp | 1 + 6 files changed, 342 insertions(+), 262 deletions(-) diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index d8e41d77e..937eb2e92 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -33,17 +33,6 @@ sub support_layers { return [ map $self->get_support_layer($_), 0..($self->support_layer_count - 1) ]; } -sub _adjust_layer_height { - my ($self, $lh) = @_; - - if ($self->print->config->z_steps_per_mm > 0) { - my $min_dz = 1/$self->print->config->z_steps_per_mm * 4; - $lh = int($lh / $min_dz + 0.5) * $min_dz; - } - - return $lh; -} - # 1) Decides Z positions of the layers, # 2) Initializes layers and their regions # 3) Slices the object meshes @@ -60,257 +49,7 @@ sub slice { $self->set_step_started(STEP_SLICE); $self->print->status_cb->(10, "Processing triangulated mesh"); - my $min_nozzle_diameter; - { - my @nozzle_diameters = map $self->print->config->get_at('nozzle_diameter', $_), - @{$self->print->object_extruders}; - - $min_nozzle_diameter = min(@nozzle_diameters); - my $lh = min($min_nozzle_diameter, $self->config->layer_height); - - $self->config->set('layer_height', $self->_adjust_layer_height($lh)); - } - - # init layers - { - $self->clear_layers; - - # make layers taking custom heights into account - my $id = 0; - my $print_z = 0; - my $first_object_layer_height = -1; - my $first_object_layer_distance = -1; - - # add raft layers - if ($self->config->raft_layers > 0) { - $id += $self->config->raft_layers; - - # raise first object layer Z by the thickness of the raft itself - # plus the extra distance required by the support material logic - my $first_layer_height = $self->config->get_value('first_layer_height'); - $print_z += $first_layer_height; - - # use a large height - my $support_material_layer_height; - { - my @nozzle_diameters = ( - map $self->print->config->get_at('nozzle_diameter', $_), - @{$self->support_material_extruders}, - ); - $support_material_layer_height = 0.75 * min(@nozzle_diameters); - } - $print_z += $support_material_layer_height * ($self->config->raft_layers - 1); - - # compute the average of all nozzles used for printing the object - my $nozzle_diameter; - { - my @nozzle_diameters = ( - map $self->print->config->get_at('nozzle_diameter', $_), @{$self->print->object_extruders} - ); - $nozzle_diameter = sum(@nozzle_diameters)/@nozzle_diameters; - } - $first_object_layer_distance = $self->_support_material->contact_distance($self->config->layer_height, $nozzle_diameter); - - # force first layer print_z according to the contact distance - # (the loop below will raise print_z by such height) - $first_object_layer_height = $first_object_layer_distance - $self->config->support_material_contact_distance; - } - - # loop until we have at least one layer and the max slice_z reaches the object height - my $slice_z = 0; - my $height = 0; - my $max_z = unscale($self->size->z); - while (($slice_z - $height) <= $max_z) { - # assign the default height to the layer according to the general settings - $height = ($id == 0) - ? $self->config->get_value('first_layer_height') - : $self->config->layer_height; - - # look for an applicable custom range - if (my $range = first { $_->[0] <= $slice_z && $_->[1] > $slice_z } @{$self->layer_height_ranges}) { - $height = $self->_adjust_layer_height($range->[2]); - - # if user set custom height to zero we should just skip the range and resume slicing over it - if ($height == 0) { - $slice_z += $range->[1] - $range->[0]; - next; - } - } - - if ($first_object_layer_height != -1 && !@{$self->layers}) { - $height = $first_object_layer_height; - $print_z += ($first_object_layer_distance - $height); - } - - $print_z += $height; - $slice_z += $height/2; - last if $slice_z > $max_z; - - ### Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z; - - $self->add_layer($id, $height, $print_z, $slice_z); - if ($self->layer_count >= 2) { - my $lc = $self->layer_count; - $self->get_layer($lc - 2)->set_upper_layer($self->get_layer($lc - 1)); - $self->get_layer($lc - 1)->set_lower_layer($self->get_layer($lc - 2)); - } - $id++; - - $slice_z += $height/2; # add the other half layer - } - } - - # Reduce or thicken the top layer in order to match the original object size. - # This is not actually related to z_steps_per_mm but we only enable it in case - # user provided that value, as it means they really care about the layer height - # accuracy and we don't provide unexpected result for people noticing the last - # layer has a different layer height. - if ($self->print->config->z_steps_per_mm > 0) { - my $first_object_layer = $self->get_layer(0); - my $last_object_layer = $self->get_layer($self->layer_count-1); - my $print_height = $last_object_layer->print_z - $first_object_layer->print_z + $first_object_layer->height; - my $diff = $print_height - unscale($self->size->z); - if ($diff < 0) { - # we need to thicken last layer - $diff = min(abs($diff), $min_nozzle_diameter - $last_object_layer->height); - $last_object_layer->set_height($last_object_layer->height + $diff); - $last_object_layer->set_print_z($last_object_layer->print_z + $diff); - } else { - # we need to reduce last layer - # prevent generation of a too small layer - my $new_height = $last_object_layer->height - $diff; - if ($new_height < $min_nozzle_diameter/2) { - $last_object_layer->set_height($new_height); - $last_object_layer->set_print_z($last_object_layer->print_z - $diff); - } - } - } - - # make sure all layers contain layer region objects for all regions - my $regions_count = $self->print->region_count; - foreach my $layer (@{ $self->layers }) { - $layer->region($_) for 0 .. ($regions_count-1); - } - - # get array of Z coordinates for slicing - my @z = map $_->slice_z, @{$self->layers}; - - # slice all non-modifier volumes - for my $region_id (0..($self->region_count - 1)) { - my $expolygons_by_layer = $self->_slice_region($region_id, \@z, 0); - for my $layer_id (0..$#$expolygons_by_layer) { - my $layerm = $self->get_layer($layer_id)->regions->[$region_id]; - $layerm->slices->clear; - foreach my $expolygon (@{ $expolygons_by_layer->[$layer_id] }) { - $layerm->slices->append(Slic3r::Surface->new( - expolygon => $expolygon, - surface_type => S_TYPE_INTERNAL, - )); - } - } - } - - # then slice all modifier volumes - if ($self->region_count > 1) { - for my $region_id (0..$self->region_count) { - my $expolygons_by_layer = $self->_slice_region($region_id, \@z, 1); - - # loop through the other regions and 'steal' the slices belonging to this one - for my $other_region_id (0..$self->region_count) { - next if $other_region_id == $region_id; - - for my $layer_id (0..$#$expolygons_by_layer) { - my $layerm = $self->get_layer($layer_id)->regions->[$region_id]; - my $other_layerm = $self->get_layer($layer_id)->regions->[$other_region_id]; - next if !defined $other_layerm; - - my $other_slices = [ map $_->p, @{$other_layerm->slices} ]; # Polygons - my $my_parts = intersection_ex( - $other_slices, - [ map @$_, @{ $expolygons_by_layer->[$layer_id] } ], - ); - next if !@$my_parts; - - # append new parts to our region - foreach my $expolygon (@$my_parts) { - $layerm->slices->append(Slic3r::Surface->new( - expolygon => $expolygon, - surface_type => S_TYPE_INTERNAL, - )); - } - - # remove such parts from original region - $other_layerm->slices->clear; - $other_layerm->slices->append(Slic3r::Surface->new( - expolygon => $_, - surface_type => S_TYPE_INTERNAL, - )) for @{ diff_ex($other_slices, [ map @$_, @$my_parts ]) }; - } - } - } - } - - # remove last layer(s) if empty - $self->delete_layer($self->layer_count - 1) - while $self->layer_count && (!map @{$_->slices}, @{$self->get_layer($self->layer_count - 1)->regions}); - - foreach my $layer (@{ $self->layers }) { - # apply size compensation - if ($self->config->xy_size_compensation != 0) { - my $delta = scale($self->config->xy_size_compensation); - if (@{$layer->regions} == 1) { - # single region - my $layerm = $layer->regions->[0]; - my $slices = [ map $_->p, @{$layerm->slices} ]; - $layerm->slices->clear; - $layerm->slices->append(Slic3r::Surface->new( - expolygon => $_, - surface_type => S_TYPE_INTERNAL, - )) for @{offset_ex($slices, $delta)}; - } else { - if ($delta < 0) { - # multiple regions, shrinking - # we apply the offset to the combined shape, then intersect it - # with the original slices for each region - my $slices = union([ map $_->p, map @{$_->slices}, @{$layer->regions} ]); - $slices = offset($slices, $delta); - foreach my $layerm (@{$layer->regions}) { - my $this_slices = intersection_ex( - $slices, - [ map $_->p, @{$layerm->slices} ], - ); - $layerm->slices->clear; - $layerm->slices->append(Slic3r::Surface->new( - expolygon => $_, - surface_type => S_TYPE_INTERNAL, - )) for @$this_slices; - } - } else { - # multiple regions, growing - # this is an ambiguous case, since it's not clear how to grow regions where they are going to overlap - # so we give priority to the first one and so on - for my $i (0..$#{$layer->regions}) { - my $layerm = $layer->regions->[$i]; - my $slices = offset_ex([ map $_->p, @{$layerm->slices} ], $delta); - if ($i > 0) { - $slices = diff_ex( - [ map @$_, @$slices ], - [ map $_->p, map @{$_->slices}, map $layer->regions->[$_], 0..($i-1) ], # slices of already processed regions - ); - } - $layerm->slices->clear; - $layerm->slices->append(Slic3r::Surface->new( - expolygon => $_, - surface_type => S_TYPE_INTERNAL, - )) for @$slices; - } - } - } - } - - # merge all regions' slices to get islands - $layer->make_slices; - } + $self->_slice; # detect slicing errors my $warning_thrown = 0; diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index b68ea6e35..a76adde6a 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -140,6 +140,9 @@ class PrintObject void detect_surfaces_type(); void process_external_surfaces(); void bridge_over_infill(); + coordf_t adjust_layer_height(coordf_t layer_height) const; + std::vector generate_object_layers(coordf_t first_layer_height); + void _slice(); std::vector _slice_region(size_t region_id, std::vector z, bool modifier); void _make_perimeters(); void _infill(); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 1aebd2c37..53e45948e 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -548,6 +548,246 @@ PrintObject::bridge_over_infill() } } +// adjust the layer height to the next multiple of the z full-step resolution +coordf_t PrintObject::adjust_layer_height(coordf_t layer_height) const +{ + coordf_t result = layer_height; + if(this->_print->config.z_steps_per_mm > 0) { + coordf_t min_dz = 1 / this->_print->config.z_steps_per_mm * 4; + result = int(layer_height / min_dz + 0.5) * min_dz; + } + + return result > 0 ? result : layer_height; +} + +// generate a vector of print_z coordinates in object coordinate system (starting with 0) but including +// the first_layer_height if provided. +std::vector PrintObject::generate_object_layers(coordf_t first_layer_height) { + + std::vector result; + + coordf_t min_nozzle_diameter = 1.0; + std::set object_extruders = this->_print->object_extruders(); + for (std::set::const_iterator it_extruder = object_extruders.begin(); it_extruder != object_extruders.end(); ++ it_extruder) { + min_nozzle_diameter = std::min(min_nozzle_diameter, this->_print->config.nozzle_diameter.get_at(*it_extruder)); + } + coordf_t layer_height = std::min(min_nozzle_diameter, this->config.layer_height.getFloat()); + layer_height = this->adjust_layer_height(layer_height); + this->config.layer_height.value = layer_height; + if(first_layer_height) { + result.push_back(first_layer_height); + } + + coordf_t print_z = first_layer_height; + coordf_t height = first_layer_height; + // loop until we have at least one layer and the max slice_z reaches the object height + while (print_z < unscale(this->size.z)) { + height = layer_height; + + // look for an applicable custom range + for (t_layer_height_ranges::const_iterator it_range = this->layer_height_ranges.begin(); it_range != this->layer_height_ranges.end(); ++ it_range) { + if(print_z >= it_range->first.first && print_z <= it_range->first.second) { + if(it_range->second > 0) { + height = it_range->second; + } + } + } + + print_z += height; + + result.push_back(print_z); + } + + // Reduce or thicken the top layer in order to match the original object size. + // This is not actually related to z_steps_per_mm but we only enable it in case + // user provided that value, as it means they really care about the layer height + // accuracy and we don't provide unexpected result for people noticing the last + // layer has a different layer height. + if (this->_print->config.z_steps_per_mm > 0 && result.size() > 1) { + coordf_t diff = result.back() - unscale(this->size.z); + int last_layer = result.size()-1; + + if (diff < 0) { + // we need to thicken last layer + coordf_t new_h = result[last_layer] - result[last_layer-1]; + new_h = std::min(min_nozzle_diameter, new_h - diff); // add (negativ) diff value + std::cout << new_h << std::endl; + result[last_layer] = result[last_layer-1] + new_h; + } else { + // we need to reduce last layer + coordf_t new_h = result[last_layer] - result[last_layer-1]; + if(min_nozzle_diameter/2 < new_h) { //prevent generation of a too small layer + new_h = std::max(min_nozzle_diameter/2, new_h - diff); // subtract (positive) diff value + std::cout << new_h << std::endl; + result[last_layer] = result[last_layer-1] + new_h; + } + } + } + return result; +} + +// 1) Decides Z positions of the layers, +// 2) Initializes layers and their regions +// 3) Slices the object meshes +// 4) Slices the modifier meshes and reclassifies the slices of the object meshes by the slices of the modifier meshes +// 5) Applies size compensation (offsets the slices in XY plane) +// 6) Replaces bad slices by the slices reconstructed from the upper/lower layer +// Resulting expolygons of layer regions are marked as Internal. +// +// this should be idempotent +void PrintObject::_slice() +{ + + coordf_t raft_height = 0; + coordf_t print_z = 0; + coordf_t height = 0; + coordf_t first_layer_height = this->config.first_layer_height.get_abs_value(this->config.layer_height.value); + + + // take raft layers into account + int id = 0; + + if (this->config.raft_layers > 0) { + id = this->config.raft_layers; + + coordf_t min_support_nozzle_diameter = 1.0; + std::set support_material_extruders = this->_print->support_material_extruders(); + for (std::set::const_iterator it_extruder = support_material_extruders.begin(); it_extruder != support_material_extruders.end(); ++ it_extruder) { + min_support_nozzle_diameter = std::min(min_support_nozzle_diameter, this->_print->config.nozzle_diameter.get_at(*it_extruder)); + } + coordf_t support_material_layer_height = 0.75 * min_support_nozzle_diameter; + + // raise first object layer Z by the thickness of the raft itself + // plus the extra distance required by the support material logic + raft_height += first_layer_height; + raft_height += support_material_layer_height * (this->config.raft_layers - 1); + + // reset for later layer generation + first_layer_height = 0; + + // detachable support + if(this->config.support_material_contact_distance > 0) { + first_layer_height = min_support_nozzle_diameter; + raft_height += this->config.support_material_contact_distance; + + } + } + + // Initialize layers and their slice heights. + std::vector slice_zs; + { + this->clear_layers(); + // All print_z values for this object, without the raft. + std::vector object_layers = this->generate_object_layers(first_layer_height); + // Reserve object layers for the raft. Last layer of the raft is the contact layer. + slice_zs.reserve(object_layers.size()); + Layer *prev = nullptr; + coordf_t lo = raft_height; + coordf_t hi = lo; + for (size_t i_layer = 0; i_layer < object_layers.size(); i_layer++) { + lo = hi; // store old value + hi = object_layers[i_layer] + raft_height; + coordf_t slice_z = 0.5 * (lo + hi) - raft_height; + Layer *layer = this->add_layer(id++, hi - lo, hi, slice_z); + slice_zs.push_back(float(slice_z)); + if (prev != nullptr) { + prev->upper_layer = layer; + layer->lower_layer = prev; + } + // Make sure all layers contain layer region objects for all regions. + for (size_t region_id = 0; region_id < this->_print->regions.size(); ++ region_id) + layer->add_region(this->print()->regions[region_id]); + prev = layer; + } + } + + if (this->print()->regions.size() == 1) { + // Optimized for a single region. Slice the single non-modifier mesh. + std::vector expolygons_by_layer = this->_slice_region(0, slice_zs, false); + for (size_t layer_id = 0; layer_id < expolygons_by_layer.size(); ++ layer_id) + this->layers[layer_id]->regions.front()->slices.append(std::move(expolygons_by_layer[layer_id]), stInternal); + } else { + // Slice all non-modifier volumes. + for (size_t region_id = 0; region_id < this->print()->regions.size(); ++ region_id) { + std::vector expolygons_by_layer = this->_slice_region(region_id, slice_zs, false); + for (size_t layer_id = 0; layer_id < expolygons_by_layer.size(); ++ layer_id) + this->layers[layer_id]->regions[region_id]->slices.append(std::move(expolygons_by_layer[layer_id]), stInternal); + } + // Slice all modifier volumes. + for (size_t region_id = 0; region_id < this->print()->regions.size(); ++ region_id) { + std::vector expolygons_by_layer = this->_slice_region(region_id, slice_zs, true); + // loop through the other regions and 'steal' the slices belonging to this one + for (size_t other_region_id = 0; other_region_id < this->print()->regions.size(); ++ other_region_id) { + if (region_id == other_region_id) + continue; + for (size_t layer_id = 0; layer_id < expolygons_by_layer.size(); ++ layer_id) { + Layer *layer = layers[layer_id]; + LayerRegion *layerm = layer->regions[region_id]; + LayerRegion *other_layerm = layer->regions[other_region_id]; + if (layerm == nullptr || other_layerm == nullptr) + continue; + Polygons other_slices = to_polygons(other_layerm->slices); + ExPolygons my_parts = intersection_ex(other_slices, to_polygons(expolygons_by_layer[layer_id])); + if (my_parts.empty()) + continue; + // Remove such parts from original region. + other_layerm->slices.set(diff_ex(other_slices, to_polygons(my_parts)), stInternal); + // Append new parts to our region. + layerm->slices.append(std::move(my_parts), stInternal); + } + } + } + } + + // remove last layer(s) if empty + bool done = false; + while (! this->layers.empty()) { + const Layer *layer = this->layers.back(); + for (size_t region_id = 0; region_id < this->print()->regions.size(); ++ region_id) + if (layer->regions[region_id] != nullptr && ! layer->regions[region_id]->slices.empty()) { + done = true; + break; + } + if(done) { + break; + } + this->delete_layer(int(this->layers.size()) - 1); + } + + for (size_t layer_id = 0; layer_id < layers.size(); ++ layer_id) { + Layer *layer = this->layers[layer_id]; + // Apply size compensation and perform clipping of multi-part objects. + float delta = float(scale_(this->config.xy_size_compensation.value)); + bool scale = delta != 0.f; + if (layer->regions.size() == 1) { + if (scale) { + // Single region, growing or shrinking. + LayerRegion *layerm = layer->regions.front(); + layerm->slices.set(offset_ex(to_expolygons(std::move(layerm->slices.surfaces)), delta), stInternal); + } + } else if (scale) { + // Multiple regions, growing, shrinking or just clipping one region by the other. + // When clipping the regions, priority is given to the first regions. + Polygons processed; + for (size_t region_id = 0; region_id < layer->regions.size(); ++ region_id) { + LayerRegion *layerm = layer->regions[region_id]; + ExPolygons slices = to_expolygons(std::move(layerm->slices.surfaces)); + if (scale) + slices = offset_ex(slices, delta); + if (region_id > 0) + // Trim by the slices of already processed regions. + slices = diff_ex(to_polygons(std::move(slices)), processed); + if (region_id + 1 < layer->regions.size()) + // Collect the already processed regions to trim the to be processed regions. + processed += to_polygons(slices); + layerm->slices.set(std::move(slices), stInternal); + } + } + // Merge all regions' slices to get islands, chain them by a shortest path. + layer->make_slices(); + } +} + // called from slice() std::vector PrintObject::_slice_region(size_t region_id, std::vector z, bool modifier) diff --git a/xs/src/libslic3r/Surface.hpp b/xs/src/libslic3r/Surface.hpp index 895d7e904..867f9a61b 100644 --- a/xs/src/libslic3r/Surface.hpp +++ b/xs/src/libslic3r/Surface.hpp @@ -62,6 +62,93 @@ to_polygons(const SurfacesConstPtr &surfaces) return pp; } +inline ExPolygons to_expolygons(const Surfaces &src) +{ + ExPolygons expolygons; + expolygons.reserve(src.size()); + for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++it) + expolygons.push_back(it->expolygon); + return expolygons; +} + +inline ExPolygons to_expolygons(Surfaces &&src) +{ + ExPolygons expolygons; + expolygons.reserve(src.size()); + for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++it) + expolygons.emplace_back(ExPolygon(std::move(it->expolygon))); + src.clear(); + return expolygons; +} + +inline ExPolygons to_expolygons(const SurfacesPtr &src) +{ + ExPolygons expolygons; + expolygons.reserve(src.size()); + for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++it) + expolygons.push_back((*it)->expolygon); + return expolygons; +} + + +// Count a nuber of polygons stored inside the vector of expolygons. +// Useful for allocating space for polygons when converting expolygons to polygons. +inline size_t number_polygons(const Surfaces &surfaces) +{ + size_t n_polygons = 0; + for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it) + n_polygons += it->expolygon.holes.size() + 1; + return n_polygons; +} + +inline size_t number_polygons(const SurfacesPtr &surfaces) +{ + size_t n_polygons = 0; + for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it) + n_polygons += (*it)->expolygon.holes.size() + 1; + return n_polygons; +} + +// Append a vector of Surfaces at the end of another vector of polygons. +inline void polygons_append(Polygons &dst, const Surfaces &src) +{ + dst.reserve(dst.size() + number_polygons(src)); + for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++ it) { + dst.push_back(it->expolygon.contour); + dst.insert(dst.end(), it->expolygon.holes.begin(), it->expolygon.holes.end()); + } +} + +inline void polygons_append(Polygons &dst, Surfaces &&src) +{ + dst.reserve(dst.size() + number_polygons(src)); + for (Surfaces::iterator it = src.begin(); it != src.end(); ++ it) { + dst.push_back(std::move(it->expolygon.contour)); + std::move(std::begin(it->expolygon.holes), std::end(it->expolygon.holes), std::back_inserter(dst)); + it->expolygon.holes.clear(); + } +} + +// Append a vector of Surfaces at the end of another vector of polygons. +inline void polygons_append(Polygons &dst, const SurfacesPtr &src) +{ + dst.reserve(dst.size() + number_polygons(src)); + for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++ it) { + dst.push_back((*it)->expolygon.contour); + dst.insert(dst.end(), (*it)->expolygon.holes.begin(), (*it)->expolygon.holes.end()); + } +} + +inline void polygons_append(Polygons &dst, SurfacesPtr &&src) +{ + dst.reserve(dst.size() + number_polygons(src)); + for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++ it) { + dst.push_back(std::move((*it)->expolygon.contour)); + std::move(std::begin((*it)->expolygon.holes), std::end((*it)->expolygon.holes), std::back_inserter(dst)); + (*it)->expolygon.holes.clear(); + } +} + } #endif diff --git a/xs/src/libslic3r/SurfaceCollection.hpp b/xs/src/libslic3r/SurfaceCollection.hpp index 6c4fe05a7..590ea4aae 100644 --- a/xs/src/libslic3r/SurfaceCollection.hpp +++ b/xs/src/libslic3r/SurfaceCollection.hpp @@ -23,6 +23,16 @@ class SurfaceCollection template bool any_bottom_contains(const T &item) const; SurfacesPtr filter_by_type(SurfaceType type); void filter_by_type(SurfaceType type, Polygons* polygons); + + void set(const SurfaceCollection &coll) { surfaces = coll.surfaces; } + void set(SurfaceCollection &&coll) { surfaces = std::move(coll.surfaces); } + void set(const ExPolygons &src, SurfaceType surfaceType) { clear(); this->append(src, surfaceType); } + void set(const ExPolygons &src, const Surface &surfaceTempl) { clear(); this->append(src, surfaceTempl); } + void set(const Surfaces &src) { clear(); this->append(src); } + void set(ExPolygons &&src, SurfaceType surfaceType) { clear(); this->append(std::move(src), surfaceType); } + void set(ExPolygons &&src, const Surface &surfaceTempl) { clear(); this->append(std::move(src), surfaceTempl); } + void set(Surfaces &&src) { clear(); this->append(std::move(src)); } + void append(const SurfaceCollection &coll); void append(const Surfaces &surfaces); void append(const ExPolygons &src, const Surface &templ); diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index c4590a69e..9863cc9af 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -126,6 +126,7 @@ _constant() void detect_surfaces_type(); void process_external_surfaces(); void bridge_over_infill(); + void _slice(); SV* _slice_region(size_t region_id, std::vector z, bool modifier) %code%{ std::vector z_f(z.begin(), z.end());