From 3b47e1a492269c07663ea043bb9465202c3bcd7d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 31 Jul 2013 15:10:11 +0200 Subject: [PATCH] New --info option to show file info (size, volume, repair stats). Removed utils/file_info.pl --- MANIFEST | 1 - README.markdown | 7 ++++-- lib/Slic3r/GUI/Plater.pm | 2 +- lib/Slic3r/Model.pm | 40 +++++++++++++++++++++++++++++ slic3r.pl | 14 +++++++++-- utils/file_info.pl | 54 ---------------------------------------- 6 files changed, 58 insertions(+), 60 deletions(-) delete mode 100755 utils/file_info.pl diff --git a/MANIFEST b/MANIFEST index ca9cacc020..3abe3b6f1e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -88,7 +88,6 @@ t/support.t t/svg.t t/vibrationlimit.t utils/amf-to-stl.pl -utils/file_info.pl utils/gcode_sectioncut.pl utils/post-processing/filament-weight.pl utils/post-processing/prowl-notification.pl diff --git a/README.markdown b/README.markdown index 46fbd0e635..ad304dc1b9 100644 --- a/README.markdown +++ b/README.markdown @@ -80,7 +80,7 @@ The author of the Silk icon set is Mark James. ## How can I invoke slic3r.pl using the command line? - Usage: slic3r.pl [ OPTIONS ] file.stl + Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ... --help Output this usage screen and exit --version Output the version of Slic3r and exit @@ -90,7 +90,10 @@ The author of the Silk icon set is Mark James. -o, --output File to output gcode to (by default, the file will be saved into the same directory as the input file using the --output-filename-format to generate the filename) - --repair Automatically repair given STL files and saves them as _fixed.obj + + Non-slicing actions (no G-code will be generated): + --repair Repair given STL files and save them as _fixed.obj + --info Output information about the supplied file(s) and exit GUI options: --no-plater Disable the plater tab diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 83fe4d7d4a..cbb5e181bb 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1125,7 +1125,7 @@ sub check_manifoldness { my $self = shift; if ($self->mesh_stats) { - if (first { $self->mesh_stats->{$_} > 0 } qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)) { + if ($self->get_model_object->needed_repair) { warn "Warning: the input file contains manifoldness errors. " . "Slic3r repaired it successfully by guessing what the correct shape should be, " . "but you might still want to inspect the G-code before printing.\n"; diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index ba873da9d5..b07125f656 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -278,6 +278,11 @@ sub split_meshes { } } +sub print_info { + my $self = shift; + $_->print_info for @{$self->objects}; +} + package Slic3r::Model::Region; use Moo; @@ -287,6 +292,7 @@ has 'attributes' => (is => 'rw', default => sub { {} }); package Slic3r::Model::Object; use Moo; +use File::Basename qw(basename); use List::Util qw(first); use Slic3r::Geometry qw(X Y Z MIN MAX move_points move_points_3D); use Storable qw(dclone); @@ -396,6 +402,7 @@ sub scale { } $self->_bounding_box->scale($factor) if defined $self->_bounding_box; + $self->mesh_stats->{volume} *= ($factor**3) if defined $self->mesh_stats; } sub rotate { @@ -425,6 +432,39 @@ sub check_manifoldness { return (first { !$_->mesh->check_manifoldness } @{$self->volumes}) ? 0 : 1; } +sub needed_repair { + my $self = shift; + + return $self->mesh_stats + && first { $self->mesh_stats->{$_} > 0 } + qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges); +} + +sub print_info { + my $self = shift; + + printf "Info about %s:\n", basename($self->input_file); + printf " size: x=%.3f y=%.3f z=%.3f\n", @{$self->size}; + if (my $stats = $self->mesh_stats) { + printf " number of facets: %d\n", $stats->{number_of_facets}; + printf " number of shells: %d\n", $stats->{number_of_parts}; + printf " volume: %.3f\n", $stats->{volume}; + if ($self->needed_repair) { + printf " needed repair: yes\n"; + printf " degenerate facets: %d\n", $stats->{degenerate_facets}; + printf " edges fixed: %d\n", $stats->{edges_fixed}; + printf " facets removed: %d\n", $stats->{facets_removed}; + printf " facets added: %d\n", $stats->{facets_added}; + printf " facets reversed: %d\n", $stats->{facets_reversed}; + printf " backwards edges: %d\n", $stats->{backwards_edges}; + } else { + printf " needed repair: no\n"; + } + } else { + printf " number of facets: %d\n", scalar(map @{$_->facets}, @{$self->volumes}); + } +} + sub clone { dclone($_[0]) } package Slic3r::Model::Volume; diff --git a/slic3r.pl b/slic3r.pl index 52becfdd17..b96b112ed1 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -34,6 +34,7 @@ BEGIN 'export-svg' => \$opt{export_svg}, 'merge|m' => \$opt{merge}, 'repair' => \$opt{repair}, + 'info' => \$opt{info}, ); foreach my $opt_key (keys %{$Slic3r::Config::Options}) { my $cli = $Slic3r::Config::Options->{$opt_key}->{cli} or next; @@ -120,6 +121,11 @@ BEGIN $_->rotate($config->rotate) for @{$model->objects}; $model->arrange_objects($config); + if ($opt{info}) { + $model->print_info; + next; + } + my $print = Slic3r::Print->new(config => $config); $print->add_model($model); $print->validate; @@ -156,7 +162,7 @@ sub usage { Slic3r $Slic3r::VERSION is a STL-to-GCODE translator for RepRap 3D printers written by Alessandro Ranellucci - http://slic3r.org/ -Usage: slic3r.pl [ OPTIONS ] file.stl +Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ... --help Output this usage screen and exit --version Output the version of Slic3r and exit @@ -166,7 +172,11 @@ sub usage { -o, --output File to output gcode to (by default, the file will be saved into the same directory as the input file using the --output-filename-format to generate the filename) - --repair Automatically repair given STL files and saves them as _fixed.obj + + Non-slicing actions (no G-code will be generated): + --repair Repair given STL files and save them as _fixed.obj + --info Output information about the supplied file(s) and exit + $j GUI options: --no-plater Disable the plater tab diff --git a/utils/file_info.pl b/utils/file_info.pl deleted file mode 100755 index 44063ab70b..0000000000 --- a/utils/file_info.pl +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/perl -# This script reads a file and outputs information about it - -use strict; -use warnings; - -BEGIN { - use FindBin; - use lib "$FindBin::Bin/../lib"; -} - -use File::Basename qw(basename); -use Getopt::Long qw(:config no_auto_abbrev); -use Slic3r; -$|++; - -my %opt = (); -{ - my %options = ( - 'help' => sub { usage() }, - ); - GetOptions(%options) or usage(1); - $ARGV[0] or usage(1); -} - -{ - my $input_file = $ARGV[0]; - die "This script doesn't support AMF yet\n" if $input_file =~ /\.amf$/i; - - my $model; - $model = Slic3r::Format::STL->read_file($input_file) if $input_file =~ /\.stl$/i; - die "Unable to read file\n" if !$model; - - printf "Info about %s:\n", basename($input_file); - my $mesh = $model->mesh; - $mesh->check_manifoldness; - printf " number of facets: %d\n", scalar @{$mesh->facets}; - printf " size: x=%s y=%s z=%s\n", @{$mesh->size}; -} - - -sub usage { - my ($exit_code) = @_; - - print <<"EOF"; -Usage: file_info.pl [ OPTIONS ] file.stl - - --help Output this usage screen and exit - -EOF - exit ($exit_code || 0); -} - -__END__