More refactoring to clean up the Print object API
This commit is contained in:
parent
d3171b1eea
commit
02df73c94b
5 changed files with 47 additions and 57 deletions
|
@ -741,30 +741,20 @@ sub export_gcode2 {
|
||||||
my @warnings = ();
|
my @warnings = ();
|
||||||
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
|
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
|
||||||
|
|
||||||
my %params = (
|
$print->status_cb(sub { $params{progressbar}->(@_) });
|
||||||
output_file => $output_file,
|
|
||||||
status_cb => sub { $params{progressbar}->(@_) },
|
|
||||||
quiet => 1,
|
|
||||||
);
|
|
||||||
if ($params{export_svg}) {
|
if ($params{export_svg}) {
|
||||||
$print->export_svg(%params);
|
$print->export_svg(%params);
|
||||||
} else {
|
} else {
|
||||||
|
$print->process;
|
||||||
$print->export_gcode(%params);
|
$print->export_gcode(%params);
|
||||||
}
|
}
|
||||||
|
$print->status_cb(undef);
|
||||||
Slic3r::GUI::warning_catcher($self, $Slic3r::have_threads ? sub {
|
Slic3r::GUI::warning_catcher($self, $Slic3r::have_threads ? sub {
|
||||||
Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $MESSAGE_DIALOG_EVENT, shared_clone([@_])));
|
Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $MESSAGE_DIALOG_EVENT, shared_clone([@_])));
|
||||||
} : undef)->($_) for @warnings;
|
} : undef)->($_) for @warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $message = "Your files were successfully sliced";
|
$params{on_completed}->();
|
||||||
if ($print->processing_time) {
|
|
||||||
$message .= ' in';
|
|
||||||
my $minutes = int($print->processing_time/60);
|
|
||||||
$message .= sprintf " %d minutes and", $minutes if $minutes;
|
|
||||||
$message .= sprintf " %.1f seconds", $print->processing_time - $minutes*60;
|
|
||||||
}
|
|
||||||
$message .= ".";
|
|
||||||
$params{on_completed}->($message);
|
|
||||||
};
|
};
|
||||||
$params{catch_error}->();
|
$params{catch_error}->();
|
||||||
}
|
}
|
||||||
|
@ -777,7 +767,8 @@ sub on_export_completed {
|
||||||
$self->{export_thread} = undef;
|
$self->{export_thread} = undef;
|
||||||
$self->statusbar->SetCancelCallback(undef);
|
$self->statusbar->SetCancelCallback(undef);
|
||||||
$self->statusbar->StopBusy;
|
$self->statusbar->StopBusy;
|
||||||
$self->statusbar->SetStatusText("G-code file exported to $self->{output_file}");
|
my $message = "G-code file exported to $self->{output_file}";
|
||||||
|
$self->statusbar->SetStatusText($message);
|
||||||
&Wx::wxTheApp->notify($message);
|
&Wx::wxTheApp->notify($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,31 +179,26 @@ sub quick_slice {
|
||||||
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
|
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
|
||||||
my %export_params = (
|
my %export_params = (
|
||||||
output_file => $output_file,
|
output_file => $output_file,
|
||||||
status_cb => sub {
|
);
|
||||||
|
$print->status_cb(sub {
|
||||||
my ($percent, $message) = @_;
|
my ($percent, $message) = @_;
|
||||||
if (&Wx::wxVERSION_STRING =~ / 2\.(8\.|9\.[2-9])/) {
|
if (&Wx::wxVERSION_STRING =~ / 2\.(8\.|9\.[2-9])/) {
|
||||||
$process_dialog->Update($percent, "$message…");
|
$process_dialog->Update($percent, "$message…");
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
if ($params{export_svg}) {
|
if ($params{export_svg}) {
|
||||||
$print->export_svg(%export_params);
|
$print->export_svg(%export_params);
|
||||||
} else {
|
} else {
|
||||||
|
$print->process;
|
||||||
$print->export_gcode(%export_params);
|
$print->export_gcode(%export_params);
|
||||||
}
|
}
|
||||||
|
$print->status_cb(undef);
|
||||||
Slic3r::GUI::warning_catcher($self)->($_) for @warnings;
|
Slic3r::GUI::warning_catcher($self)->($_) for @warnings;
|
||||||
}
|
}
|
||||||
$process_dialog->Destroy;
|
$process_dialog->Destroy;
|
||||||
undef $process_dialog;
|
undef $process_dialog;
|
||||||
|
|
||||||
my $message = "$input_file_basename was successfully sliced";
|
my $message = "$input_file_basename was successfully sliced.";
|
||||||
if ($print->processing_time) {
|
|
||||||
$message .= ' in';
|
|
||||||
my $minutes = int($print->processing_time/60);
|
|
||||||
$message .= sprintf " %d minutes and", $minutes if $minutes;
|
|
||||||
$message .= sprintf " %.1f seconds", $print->processing_time - $minutes*60;
|
|
||||||
}
|
|
||||||
$message .= ".";
|
|
||||||
&Wx::wxTheApp->notify($message);
|
&Wx::wxTheApp->notify($message);
|
||||||
Wx::MessageDialog->new($self, $message, 'Slicing Done!',
|
Wx::MessageDialog->new($self, $message, 'Slicing Done!',
|
||||||
wxOK | wxICON_INFORMATION)->ShowModal;
|
wxOK | wxICON_INFORMATION)->ShowModal;
|
||||||
|
|
|
@ -9,12 +9,11 @@ use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX PI scale unscale move_points c
|
||||||
convex_hull);
|
convex_hull);
|
||||||
use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex intersection offset
|
use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex intersection offset
|
||||||
offset2 union_pt_chained JT_ROUND JT_SQUARE);
|
offset2 union_pt_chained JT_ROUND JT_SQUARE);
|
||||||
use Time::HiRes qw(gettimeofday tv_interval);
|
|
||||||
|
|
||||||
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => 1);
|
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => 1);
|
||||||
has 'extra_variables' => (is => 'rw', default => sub {{}});
|
has 'extra_variables' => (is => 'rw', default => sub {{}});
|
||||||
has 'objects' => (is => 'rw', default => sub {[]});
|
has 'objects' => (is => 'rw', default => sub {[]});
|
||||||
has 'processing_time' => (is => 'rw');
|
has 'status_cb' => (is => 'rw');
|
||||||
has 'extruders' => (is => 'rw', default => sub {[]});
|
has 'extruders' => (is => 'rw', default => sub {[]});
|
||||||
has 'regions' => (is => 'rw', default => sub {[]});
|
has 'regions' => (is => 'rw', default => sub {[]});
|
||||||
has 'support_material_flow' => (is => 'rw');
|
has 'support_material_flow' => (is => 'rw');
|
||||||
|
@ -304,13 +303,11 @@ sub _simplify_slices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub export_gcode {
|
sub process {
|
||||||
my $self = shift;
|
my ($self) = @_;
|
||||||
my %params = @_;
|
|
||||||
|
|
||||||
$self->init_extruders;
|
$self->init_extruders;
|
||||||
my $status_cb = $params{status_cb} || sub {};
|
my $status_cb = $self->status_cb // sub {};
|
||||||
my $t0 = [gettimeofday];
|
|
||||||
|
|
||||||
# skein the STL into layers
|
# skein the STL into layers
|
||||||
# each layer has surfaces with holes
|
# each layer has surfaces with holes
|
||||||
|
@ -427,6 +424,13 @@ sub export_gcode {
|
||||||
eval "use Slic3r::Test::SectionCut";
|
eval "use Slic3r::Test::SectionCut";
|
||||||
Slic3r::Test::SectionCut->new(print => $self)->export_svg("section_cut.svg");
|
Slic3r::Test::SectionCut->new(print => $self)->export_svg("section_cut.svg");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub export_gcode {
|
||||||
|
my $self = shift;
|
||||||
|
my %params = @_;
|
||||||
|
|
||||||
|
my $status_cb = $self->status_cb // sub {};
|
||||||
|
|
||||||
# output everything to a G-code file
|
# output everything to a G-code file
|
||||||
my $output_file = $self->expanded_output_filepath($params{output_file});
|
my $output_file = $self->expanded_output_filepath($params{output_file});
|
||||||
|
@ -442,19 +446,6 @@ sub export_gcode {
|
||||||
system($_, $output_file);
|
system($_, $output_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# output some statistics
|
|
||||||
unless ($params{quiet}) {
|
|
||||||
$self->processing_time(tv_interval($t0));
|
|
||||||
printf "Done. Process took %d minutes and %.3f seconds\n",
|
|
||||||
int($self->processing_time/60),
|
|
||||||
$self->processing_time - int($self->processing_time/60)*60;
|
|
||||||
|
|
||||||
# TODO: more statistics!
|
|
||||||
print map sprintf("Filament required: %.1fmm (%.1fcm3)\n",
|
|
||||||
$_->absolute_E, $_->extruded_volume/1000),
|
|
||||||
@{$self->extruders};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub export_svg {
|
sub export_svg {
|
||||||
|
|
|
@ -119,6 +119,7 @@ sub gcode {
|
||||||
my ($print) = @_;
|
my ($print) = @_;
|
||||||
|
|
||||||
my $fh = IO::Scalar->new(\my $gcode);
|
my $fh = IO::Scalar->new(\my $gcode);
|
||||||
|
$print->process;
|
||||||
$print->export_gcode(output_fh => $fh, quiet => 1);
|
$print->export_gcode(output_fh => $fh, quiet => 1);
|
||||||
$fh->close;
|
$fh->close;
|
||||||
|
|
||||||
|
|
28
slic3r.pl
28
slic3r.pl
|
@ -13,6 +13,7 @@ use List::Util qw(first);
|
||||||
use POSIX qw(setlocale LC_NUMERIC);
|
use POSIX qw(setlocale LC_NUMERIC);
|
||||||
use Slic3r;
|
use Slic3r;
|
||||||
use Slic3r::Geometry qw(X Y);
|
use Slic3r::Geometry qw(X Y);
|
||||||
|
use Time::HiRes qw(gettimeofday tv_interval);
|
||||||
$|++;
|
$|++;
|
||||||
|
|
||||||
our %opt = ();
|
our %opt = ();
|
||||||
|
@ -151,21 +152,32 @@ if (@ARGV) { # slicing from command line
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $print = Slic3r::Print->new(config => $config);
|
my $print = Slic3r::Print->new(
|
||||||
$print->add_model_object($_) for @{$model->objects};
|
config => $config,
|
||||||
undef $model; # free memory
|
|
||||||
$print->validate;
|
|
||||||
my %params = (
|
|
||||||
output_file => $opt{output},
|
|
||||||
status_cb => sub {
|
status_cb => sub {
|
||||||
my ($percent, $message) = @_;
|
my ($percent, $message) = @_;
|
||||||
printf "=> %s\n", $message;
|
printf "=> %s\n", $message;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
$print->add_model_object($_) for @{$model->objects};
|
||||||
|
undef $model; # free memory
|
||||||
|
$print->validate;
|
||||||
if ($opt{export_svg}) {
|
if ($opt{export_svg}) {
|
||||||
$print->export_svg(%params);
|
$print->export_svg(output_file => $opt{output});
|
||||||
} else {
|
} else {
|
||||||
$print->export_gcode(%params);
|
my $t0 = [gettimeofday];
|
||||||
|
$print->process;
|
||||||
|
$print->export_gcode(output_file => $opt{output});
|
||||||
|
|
||||||
|
# output some statistics
|
||||||
|
{
|
||||||
|
my $duration = tv_interval($t0);
|
||||||
|
printf "Done. Process took %d minutes and %.3f seconds\n",
|
||||||
|
int($duration/60), ($duration - int($duration/60)*60); # % truncates to integer
|
||||||
|
}
|
||||||
|
print map sprintf("Filament required: %.1fmm (%.1fcm3)\n",
|
||||||
|
$_->absolute_E, $_->extruded_volume/1000),
|
||||||
|
@{$print->extruders};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue