Fixed order of loading the configs into Print / PrintObjects

and loading the 3d print path preview.
This commit is contained in:
bubnikv 2017-05-30 17:24:50 +02:00
parent 41a4df0a38
commit efb1fd2066
6 changed files with 77 additions and 55 deletions

View file

@ -910,14 +910,12 @@ sub UseVBOs {
if (! defined ($self->{use_VBOs})) {
# This is a special path for wxWidgets on GTK, where an OpenGL context is initialized
# first when an OpenGL widget is shown for the first time. How ugly.
# It seems like the wipe tower configuration fills in the VBOs before the window is created.
# Therefore it is safer to wait for the first screen refresh on Windows and OSX as well.
# return 0 if (! $self->init && $^O eq 'linux');
return 0 if (! $self->init);
return 0 if (! $self->init && $^O eq 'linux');
# Don't use VBOs if anything fails.
$self->{use_VBOs} = 0;
if ($self->GetContext) {
$self->SetCurrent($self->GetContext);
Slic3r::GUI::_3DScene::_glew_init;
my @gl_version = split(/\./, glGetString(GL_VERSION));
$self->{use_VBOs} = int($gl_version[0]) >= 2;
# print "UseVBOs $self OpenGL major: $gl_version[0], minor: $gl_version[1]. Use VBOs: ", $self->{use_VBOs}, "\n";
@ -1023,8 +1021,6 @@ sub InitGL {
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_MULTISAMPLE);
Slic3r::GUI::_3DScene::_glew_init;
if ($self->UseVBOs) {
my $shader = new Slic3r::GUI::_3DScene::GLShader;
if (! $shader->load($self->_fragment_shader_Gouraud, $self->_vertex_shader_Gouraud)) {

View file

@ -1202,11 +1202,7 @@ sub schedule_background_process {
# The timer is started by schedule_background_process(),
sub async_apply_config {
my ($self) = @_;
# reset preview canvases
$self->{toolpaths2D}->reload_print if $self->{toolpaths2D};
$self->{preview3D}->reload_print if $self->{preview3D};
# pause process thread before applying new config
# since we don't want to touch data that is being used by the threads
$self->pause_background_process;
@ -1231,6 +1227,11 @@ sub async_apply_config {
# schedule a new process thread in case it wasn't running
$self->start_background_process;
# Reset preview canvases. If the print has been invalidated, the preview canvases will be cleared.
# Otherwise they will be just refreshed.
$self->{toolpaths2D}->reload_print if $self->{toolpaths2D};
$self->{preview3D}->reload_print if $self->{preview3D};
}
sub start_background_process {
@ -1817,8 +1818,10 @@ sub on_config_change {
$self->{"btn_layer_editing"}->Enable;
}
}
} elsif ($opt_key eq 'extruder_color') {
} elsif ($opt_key eq 'extruder_colour') {
$update_scheduled = 1;
my $extruder_colors = $config->get('extruder_colour');
$self->{preview3D}->set_number_extruders(scalar(@{$extruder_colors}));
}
}

View file

@ -8,7 +8,7 @@ use Wx qw(:misc :sizer :slider :statictext :keycode wxWHITE);
use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN EVT_CHECKBOX);
use base qw(Wx::Panel Class::Accessor);
__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider_low slider_high single_layer color_by_extruder));
__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider_low slider_high single_layer));
sub new {
my $class = shift;
@ -16,6 +16,8 @@ sub new {
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition);
$self->{config} = $config;
$self->{number_extruders} = 1;
$self->{preferred_color_mode} = 'feature';
# init GUI elements
my $canvas = Slic3r::GUI::3DScene->new($self);
@ -54,7 +56,7 @@ sub new {
$z_label_high->SetFont($Slic3r::GUI::small_font);
$self->single_layer(0);
$self->color_by_extruder(0);
$self->{color_by_extruder} = 0;
my $checkbox_singlelayer = $self->{checkbox_singlelayer} = Wx::CheckBox->new($self, -1, "1 Layer");
my $checkbox_color_by_extruder = $self->{checkbox_color_by_extruder} = Wx::CheckBox->new($self, -1, "Tool");
@ -112,7 +114,8 @@ sub new {
}
});
EVT_CHECKBOX($self, $checkbox_color_by_extruder, sub {
$self->color_by_extruder($checkbox_color_by_extruder->GetValue());
$self->{color_by_extruder} = $checkbox_color_by_extruder->GetValue();
$self->{preferred_color_mode} = $self->{color_by_extruder} ? 'tool' : 'feature';
$self->reload_print;
});
@ -189,10 +192,21 @@ sub load_print {
$self->slider_high->Show;
$self->Layout;
my $by_tool = $self->{color_by_extruder};
if ($self->{preferred_color_mode} eq 'tool_or_feature') {
# It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature.
# Color by feature if it is a single extruder print.
my $extruders = $self->{print}->extruders;
$by_tool = scalar(@{$extruders}) > 1;
$self->{color_by_extruder} = $by_tool;
$self->{checkbox_color_by_extruder}->SetValue($by_tool);
$self->{preferred_color_mode} = 'tool_or_feature';
}
# Collect colors per extruder.
# Leave it empty, if the print should be colored by a feature.
my @colors = ();
if ($self->color_by_extruder) {
if ($by_tool) {
my @extruder_colors = @{$self->{config}->extruder_colour};
my @filament_colors = @{$self->{config}->filament_colour};
for (my $i = 0; $i <= $#extruder_colors; $i += 1) {
@ -264,4 +278,15 @@ sub set_bed_shape {
$self->canvas->set_bed_shape($bed_shape);
}
sub set_number_extruders {
my ($self, $number_extruders) = @_;
if ($self->{number_extruders} != $number_extruders) {
$self->{number_extruders} = $number_extruders;
my $by_tool = $number_extruders > 1;
$self->{color_by_extruder} = $by_tool;
$self->{checkbox_color_by_extruder}->SetValue($by_tool);
$self->{preferred_color_mode} = $by_tool ? 'tool_or_feature' : 'feature';
}
}
1;