Skip to content

Commit

Permalink
New --info option to show file info (size, volume, repair stats). Rem…
Browse files Browse the repository at this point in the history
…oved utils/file_info.pl
  • Loading branch information
alranel committed Jul 31, 2013
1 parent 1479d69 commit 3b47e1a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 60 deletions.
1 change: 0 additions & 1 deletion MANIFEST
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions README.markdown
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Slic3r/GUI/Plater.pm
Expand Up @@ -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";
Expand Down
40 changes: 40 additions & 0 deletions lib/Slic3r/Model.pm
Expand Up @@ -278,6 +278,11 @@ sub split_meshes {
}
}

sub print_info {
my $self = shift;
$_->print_info for @{$self->objects};
}

package Slic3r::Model::Region;
use Moo;

Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions slic3r.pl
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -156,7 +162,7 @@ sub usage {
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
Expand All @@ -166,7 +172,11 @@ sub usage {
-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
Expand Down
54 changes: 0 additions & 54 deletions utils/file_info.pl

This file was deleted.

0 comments on commit 3b47e1a

Please sign in to comment.