Disabled the new Slic3r version check until we have a server set up

for the Slic3r Prusa Edition.

Hopefully a fix of https://github.com/prusa3d/Slic3r/issues/258
by moving the 2D thumbnail generation to the main thread and
forcing the simple 2D convex hull for even the small objects.
This commit is contained in:
bubnikv 2017-06-12 14:25:35 +02:00
parent 02ab92ea65
commit f408f08850
5 changed files with 118 additions and 136 deletions

View file

@ -34,7 +34,6 @@ use constant TB_SETTINGS => &Wx::NewId;
use constant TB_LAYER_EDITING => &Wx::NewId;
# package variables to avoid passing lexicals to threads
our $THUMBNAIL_DONE_EVENT : shared = Wx::NewEventType;
our $PROGRESS_BAR_EVENT : shared = Wx::NewEventType;
our $ERROR_EVENT : shared = Wx::NewEventType;
# Emitted from the worker thread when the G-code export is finished.
@ -307,14 +306,6 @@ sub new {
for grep defined($_),
$self, $self->{canvas}, $self->{canvas3D}, $self->{preview3D}, $self->{list};
EVT_COMMAND($self, -1, $THUMBNAIL_DONE_EVENT, sub {
my ($self, $event) = @_;
my ($obj_idx) = @{$event->GetData};
return if !$self->{objects}[$obj_idx]; # object was deleted before thumbnail generation completed
$self->on_thumbnail_made($obj_idx);
});
EVT_COMMAND($self, -1, $PROGRESS_BAR_EVENT, sub {
my ($self, $event) = @_;
my ($percent, $message) = @{$event->GetData};
@ -803,7 +794,7 @@ sub load_model_objects {
$self->{list}->SetItem($obj_idx, 1, $model_object->instances_count);
$self->{list}->SetItem($obj_idx, 2, ($model_object->instances->[0]->scaling_factor * 100) . "%");
$self->make_thumbnail($obj_idx);
$self->reset_thumbnail($obj_idx);
}
$self->arrange if $need_arrange;
$self->update;
@ -988,10 +979,7 @@ sub rotate {
my $model_object = $self->{model}->objects->[$obj_idx];
my $model_instance = $model_object->instances->[0];
# we need thumbnail to be computed before allowing rotation
return if !$object->thumbnail;
if (!defined $angle) {
my $axis_name = $axis == X ? 'X' : $axis == Y ? 'Y' : 'Z';
my $default = $axis == Z ? rad2deg($model_instance->rotation) : 0;
@ -1016,7 +1004,7 @@ sub rotate {
# realign object to Z = 0
$model_object->center_around_origin;
$self->make_thumbnail($obj_idx);
$self->reset_thumbnail($obj_idx);
}
$model_object->update_bounding_box;
@ -1048,7 +1036,7 @@ sub mirror {
# realign object to Z = 0
$model_object->center_around_origin;
$self->make_thumbnail($obj_idx);
$self->reset_thumbnail($obj_idx);
# update print and start background processing
$self->stop_background_process;
@ -1068,9 +1056,6 @@ sub changescale {
my $model_object = $self->{model}->objects->[$obj_idx];
my $model_instance = $model_object->instances->[0];
# we need thumbnail to be computed before allowing scaling
return if !$object->thumbnail;
my $object_size = $model_object->bounding_box->size;
my $bed_size = Slic3r::Polygon->new_scale(@{$self->{config}->bed_shape})->bounding_box->size;
@ -1101,7 +1086,7 @@ sub changescale {
#FIXME Scale the layer height profile when $axis == Z?
#FIXME Scale the layer height ranges $axis == Z?
# object was already aligned to Z = 0, so no need to realign it
$self->make_thumbnail($obj_idx);
$self->reset_thumbnail($obj_idx);
} else {
my $scale;
if ($tosize) {
@ -1621,12 +1606,6 @@ sub reload_from_disk {
}
$self->remove($obj_idx);
# Trigger thumbnail generation again, because the remove() method altered
# object indexes before background thumbnail generation called its completion
# event, so the on_thumbnail_made callback is called with the wrong $obj_idx.
# When porting to C++ we'll probably have cleaner ways to do this.
$self->make_thumbnail($_-1) for @new_obj_idx;
}
sub export_object_stl {
@ -1674,36 +1653,9 @@ sub _get_export_file {
return $output_file;
}
sub make_thumbnail {
my $self = shift;
my ($obj_idx) = @_;
my $plater_object = $self->{objects}[$obj_idx];
$plater_object->thumbnail(Slic3r::ExPolygon::Collection->new);
my $cb = sub {
$plater_object->make_thumbnail($self->{model}, $obj_idx);
if ($Slic3r::have_threads) {
Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $THUMBNAIL_DONE_EVENT, shared_clone([ $obj_idx ])));
Slic3r::thread_cleanup();
threads->exit;
} else {
$self->on_thumbnail_made($obj_idx);
}
};
@_ = ();
$Slic3r::have_threads
? threads->create(sub { $cb->(); Slic3r::thread_cleanup(); })->detach
: $cb->();
}
sub on_thumbnail_made {
my $self = shift;
my ($obj_idx) = @_;
$self->{objects}[$obj_idx]->transform_thumbnail($self->{model}, $obj_idx);
$self->{canvas}->Refresh;
sub reset_thumbnail {
my ($self, $obj_idx) = @_;
$self->{objects}[$obj_idx]->thumbnail(undef);
}
# this method gets called whenever print center is changed or the objects' bounding box changes
@ -1727,7 +1679,8 @@ sub update {
} else {
$self->resume_background_process;
}
$self->{canvas}->reload_scene if $self->{canvas};
$self->{canvas3D}->reload_scene if $self->{canvas3D};
$self->{preview3D}->reload_print if $self->{preview3D};
}
@ -1942,7 +1895,7 @@ sub object_settings_dialog {
if ($dlg->PartsChanged) {
# recenter and re-align to Z = 0
$model_object->center_around_origin;
$self->make_thumbnail($obj_idx);
$self->reset_thumbnail($obj_idx);
}
# update print
@ -1950,6 +1903,7 @@ sub object_settings_dialog {
$self->stop_background_process;
$self->{print}->reload_object($obj_idx);
$self->schedule_background_process;
$self->{canvas}->reload_scene if $self->{canvas};
$self->{canvas3D}->reload_scene if $self->{canvas3D};
} else {
$self->resume_background_process;
@ -2245,18 +2199,19 @@ sub make_thumbnail {
$self->thumbnail->clear;
my $mesh = $model->objects->[$obj_idx]->raw_mesh;
if ($mesh->facets_count <= 5000) {
# remove polygons with area <= 1mm
my $area_threshold = Slic3r::Geometry::scale 1;
$self->thumbnail->append(
grep $_->area >= $area_threshold,
@{ $mesh->horizontal_projection }, # horizontal_projection returns scaled expolygons
);
$self->thumbnail->simplify(0.5);
} else {
#FIXME The "correct" variant could be extremely slow.
# if ($mesh->facets_count <= 5000) {
# # remove polygons with area <= 1mm
# my $area_threshold = Slic3r::Geometry::scale 1;
# $self->thumbnail->append(
# grep $_->area >= $area_threshold,
# @{ $mesh->horizontal_projection }, # horizontal_projection returns scaled expolygons
# );
# $self->thumbnail->simplify(0.5);
# } else {
my $convex_hull = Slic3r::ExPolygon->new($mesh->convex_hull);
$self->thumbnail->append($convex_hull);
}
# }
return $self->thumbnail;
}

View file

@ -13,10 +13,6 @@ use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL);
use Wx::Event qw(EVT_MOUSE_EVENTS EVT_PAINT EVT_ERASE_BACKGROUND EVT_SIZE);
use base 'Wx::Panel';
use constant CANVAS_TEXT => join('-', +(localtime)[3,4]) eq '13-8'
? 'What do you want to print today? ™' # Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap.
: 'Drag your objects here';
sub new {
my $class = shift;
my ($parent, $size, $objects, $model, $config) = @_;
@ -128,7 +124,11 @@ sub repaint {
if (!@{$self->{objects}}) {
$dc->SetTextForeground(Wx::Colour->new(150,50,50));
$dc->SetFont(Wx::Font->new(14, wxDEFAULT, wxNORMAL, wxNORMAL));
$dc->DrawLabel(CANVAS_TEXT, Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
$dc->DrawLabel(
join('-', +(localtime)[3,4]) eq '13-8'
? 'What do you want to print today? ™' # Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap.
: 'Drag your objects here',
Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
}
# draw thumbnails
@ -340,4 +340,32 @@ sub point_to_model_units {
);
}
sub reload_scene {
my ($self, $force) = @_;
if (! $self->IsShown && ! $force) {
$self->{reload_delayed} = 1;
return;
}
$self->{reload_delayed} = 0;
foreach my $obj_idx (0..$#{$self->{model}->objects}) {
my $plater_object = $self->{objects}[$obj_idx];
next if $plater_object->thumbnail;
# The thumbnail is not valid, update it with a convex hull of an object.
$plater_object->thumbnail(Slic3r::ExPolygon::Collection->new);
$plater_object->make_thumbnail($self->{model}, $obj_idx);
$plater_object->transform_thumbnail($self->{model}, $obj_idx);
}
$self->Refresh;
}
# Called by the Platter wxNotebook when this page is activated.
sub OnActivate {
my ($self) = @_;
$self->reload_scene(1) if ($self->{reload_delayed});
}
1;

View file

@ -30,14 +30,14 @@ sub new {
default => $Slic3r::GUI::Settings->{_}{mode},
width => 100,
));
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
opt_id => 'version_check',
type => 'bool',
label => 'Check for updates',
tooltip => 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.',
default => $Slic3r::GUI::Settings->{_}{version_check} // 1,
readonly => !wxTheApp->have_version_check,
));
# $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
# opt_id => 'version_check',
# type => 'bool',
# label => 'Check for updates',
# tooltip => 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.',
# default => $Slic3r::GUI::Settings->{_}{version_check} // 1,
# readonly => !wxTheApp->have_version_check,
# ));
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
opt_id => 'remember_output_path',
type => 'bool',