mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-07 14:04:11 -06:00
Partial work for background processing
This commit is contained in:
parent
97231327e0
commit
d9e7a50a6e
7 changed files with 164 additions and 64 deletions
|
@ -33,6 +33,7 @@ our $PROGRESS_BAR_EVENT : shared = Wx::NewEventType;
|
|||
our $MESSAGE_DIALOG_EVENT : shared = Wx::NewEventType;
|
||||
our $EXPORT_COMPLETED_EVENT : shared = Wx::NewEventType;
|
||||
our $EXPORT_FAILED_EVENT : shared = Wx::NewEventType;
|
||||
our $PROCESS_COMPLETED_EVENT : shared = Wx::NewEventType;
|
||||
|
||||
use constant CANVAS_SIZE => [335,335];
|
||||
use constant FILAMENT_CHOOSERS_SPACING => 3;
|
||||
|
@ -218,6 +219,14 @@ sub new {
|
|||
$self->on_export_failed;
|
||||
});
|
||||
|
||||
EVT_COMMAND($self, -1, $PROCESS_COMPLETED_EVENT, sub {
|
||||
my ($self, $event) = @_;
|
||||
|
||||
Slic3r::debugf "Background processing completed.\n";
|
||||
$self->{process_thread}->detach if $self->{process_thread};
|
||||
$self->{process_thread} = undef;
|
||||
});
|
||||
|
||||
$self->{canvas}->update_bed_size;
|
||||
$self->update;
|
||||
|
||||
|
@ -439,6 +448,9 @@ sub objects_loaded {
|
|||
$self->{list}->Update;
|
||||
$self->{list}->Select($obj_idxs->[-1], 1);
|
||||
$self->object_list_changed;
|
||||
|
||||
# TODO: start timer for new export thread
|
||||
$self->start_background_process;
|
||||
}
|
||||
|
||||
sub remove {
|
||||
|
@ -664,10 +676,60 @@ sub split_object {
|
|||
$self->load_model_objects(@model_objects);
|
||||
}
|
||||
|
||||
sub start_background_process {
|
||||
my ($self) = @_;
|
||||
|
||||
return if !$Slic3r::have_threads;
|
||||
return if !@{$self->{objects}};
|
||||
|
||||
if ($self->{process_thread}) {
|
||||
warn "Can't start new process thread because one is already running\n";
|
||||
return;
|
||||
}
|
||||
|
||||
# It looks like declaring a local $SIG{__WARN__} prevents the ugly
|
||||
# "Attempt to free unreferenced scalar" warning...
|
||||
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
|
||||
|
||||
# don't start process thread if config is not valid
|
||||
eval {
|
||||
# this will throw errors if config is not valid
|
||||
$self->skeinpanel->config->validate;
|
||||
$self->{print}->validate;
|
||||
};
|
||||
return if $@;
|
||||
|
||||
# apply extra variables
|
||||
{
|
||||
my $extra = $self->skeinpanel->extra_variables;
|
||||
$self->{print}->placeholder_parser->set($_, $extra->{$_}) for keys %$extra;
|
||||
}
|
||||
|
||||
# start thread
|
||||
$self->{process_thread} = threads->create(sub {
|
||||
$self->{print}->process;
|
||||
Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $PROCESS_COMPLETED_EVENT, undef));
|
||||
Slic3r::thread_cleanup();
|
||||
});
|
||||
Slic3r::debugf "Background processing started.\n";
|
||||
}
|
||||
|
||||
sub stop_background_process {
|
||||
my ($self) = @_;
|
||||
|
||||
if ($self->{process_thread}) {
|
||||
Slic3r::debugf "Killing background process.\n";
|
||||
$self->{process_thread}->kill('KILL')->join;
|
||||
$self->{process_thread} = undef;
|
||||
} else {
|
||||
Slic3r::debugf "No background process running.\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub export_gcode {
|
||||
my $self = shift;
|
||||
|
||||
if ($self->{export_thread}) {
|
||||
if ($self->{export_gcode_output_file}) {
|
||||
Wx::MessageDialog->new($self, "Another slicing job is currently running.", 'Error', wxOK | wxICON_ERROR)->ShowModal;
|
||||
return;
|
||||
}
|
||||
|
@ -912,6 +974,7 @@ sub update {
|
|||
sub on_config_change {
|
||||
my $self = shift;
|
||||
my ($opt_key, $value) = @_;
|
||||
|
||||
if ($opt_key eq 'extruders_count' && defined $value) {
|
||||
my $choices = $self->{preset_choosers}{filament};
|
||||
while (@$choices < $value) {
|
||||
|
@ -937,6 +1000,17 @@ sub on_config_change {
|
|||
}
|
||||
$self->update if $opt_key eq 'print_center';
|
||||
}
|
||||
|
||||
return if !$self->skeinpanel->is_loaded;
|
||||
# TODO: pause export thread
|
||||
my $invalidated = $self->{print}->apply_config($self->skeinpanel->config);
|
||||
if ($invalidated) {
|
||||
# kill export thread
|
||||
$self->stop_background_process;
|
||||
|
||||
# TODO: start timer for new export thread
|
||||
$self->start_background_process;
|
||||
}
|
||||
}
|
||||
|
||||
sub list_item_deselected {
|
||||
|
|
|
@ -31,6 +31,7 @@ sub new {
|
|||
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||
$self->{mode} = $params{mode};
|
||||
$self->{mode} = 'expert' if $self->{mode} !~ /^(?:simple|expert)$/;
|
||||
$self->{loaded} = 0;
|
||||
|
||||
$self->{tabpanel} = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL);
|
||||
$self->{tabpanel}->AddPage($self->{plater} = Slic3r::GUI::Plater->new($self->{tabpanel}), "Plater")
|
||||
|
@ -81,9 +82,15 @@ sub new {
|
|||
$self->SetSizer($sizer);
|
||||
$self->Layout;
|
||||
|
||||
$self->{loaded} = 1;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub is_loaded {
|
||||
my ($self) = @_;
|
||||
return $self->{loaded};
|
||||
}
|
||||
|
||||
sub quick_slice {
|
||||
my $self = shift;
|
||||
my %params = @_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue