New --info option to show file info (size, volume, repair stats). Removed utils/file_info.pl

grow-support
Alessandro Ranellucci 2013-07-31 15:10:11 +02:00
parent 1479d6933b
commit 3b47e1a492
6 changed files with 58 additions and 60 deletions

View File

@ -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

View File

@ -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> 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 <name>_fixed.obj
--info Output information about the supplied file(s) and exit
GUI options:
--no-plater Disable the plater tab

View File

@ -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";

View File

@ -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;

View File

@ -34,6 +34,7 @@ my %cli_options = ();
'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 @@ if (@ARGV) { # slicing from command line
$_->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 @@ EOF
Slic3r $Slic3r::VERSION is a STL-to-GCODE translator for RepRap 3D printers
written by Alessandro Ranellucci <aar\@cpan.org> - 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 @@ Usage: slic3r.pl [ OPTIONS ] file.stl
-o, --output <file> 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 <name>_fixed.obj
--info Output information about the supplied file(s) and exit
$j
GUI options:
--no-plater Disable the plater tab

View File

@ -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__