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})) { if (! defined ($self->{use_VBOs})) {
# This is a special path for wxWidgets on GTK, where an OpenGL context is initialized # 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. # 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. return 0 if (! $self->init && $^O eq 'linux');
# 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);
# Don't use VBOs if anything fails. # Don't use VBOs if anything fails.
$self->{use_VBOs} = 0; $self->{use_VBOs} = 0;
if ($self->GetContext) { if ($self->GetContext) {
$self->SetCurrent($self->GetContext); $self->SetCurrent($self->GetContext);
Slic3r::GUI::_3DScene::_glew_init;
my @gl_version = split(/\./, glGetString(GL_VERSION)); my @gl_version = split(/\./, glGetString(GL_VERSION));
$self->{use_VBOs} = int($gl_version[0]) >= 2; $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"; # 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_COLOR_MATERIAL);
glEnable(GL_MULTISAMPLE); glEnable(GL_MULTISAMPLE);
Slic3r::GUI::_3DScene::_glew_init;
if ($self->UseVBOs) { if ($self->UseVBOs) {
my $shader = new Slic3r::GUI::_3DScene::GLShader; my $shader = new Slic3r::GUI::_3DScene::GLShader;
if (! $shader->load($self->_fragment_shader_Gouraud, $self->_vertex_shader_Gouraud)) { if (! $shader->load($self->_fragment_shader_Gouraud, $self->_vertex_shader_Gouraud)) {

View file

@ -1203,10 +1203,6 @@ sub schedule_background_process {
sub async_apply_config { sub async_apply_config {
my ($self) = @_; 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 # pause process thread before applying new config
# since we don't want to touch data that is being used by the threads # since we don't want to touch data that is being used by the threads
$self->pause_background_process; $self->pause_background_process;
@ -1231,6 +1227,11 @@ sub async_apply_config {
# schedule a new process thread in case it wasn't running # schedule a new process thread in case it wasn't running
$self->start_background_process; $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 { sub start_background_process {
@ -1817,8 +1818,10 @@ sub on_config_change {
$self->{"btn_layer_editing"}->Enable; $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 Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN EVT_CHECKBOX);
use base qw(Wx::Panel Class::Accessor); 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 { sub new {
my $class = shift; my $class = shift;
@ -16,6 +16,8 @@ sub new {
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition); my $self = $class->SUPER::new($parent, -1, wxDefaultPosition);
$self->{config} = $config; $self->{config} = $config;
$self->{number_extruders} = 1;
$self->{preferred_color_mode} = 'feature';
# init GUI elements # init GUI elements
my $canvas = Slic3r::GUI::3DScene->new($self); my $canvas = Slic3r::GUI::3DScene->new($self);
@ -54,7 +56,7 @@ sub new {
$z_label_high->SetFont($Slic3r::GUI::small_font); $z_label_high->SetFont($Slic3r::GUI::small_font);
$self->single_layer(0); $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_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"); 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 { 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; $self->reload_print;
}); });
@ -189,10 +192,21 @@ sub load_print {
$self->slider_high->Show; $self->slider_high->Show;
$self->Layout; $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. # Collect colors per extruder.
# Leave it empty, if the print should be colored by a feature. # Leave it empty, if the print should be colored by a feature.
my @colors = (); my @colors = ();
if ($self->color_by_extruder) { if ($by_tool) {
my @extruder_colors = @{$self->{config}->extruder_colour}; my @extruder_colors = @{$self->{config}->extruder_colour};
my @filament_colors = @{$self->{config}->filament_colour}; my @filament_colors = @{$self->{config}->filament_colour};
for (my $i = 0; $i <= $#extruder_colors; $i += 1) { for (my $i = 0; $i <= $#extruder_colors; $i += 1) {
@ -264,4 +278,15 @@ sub set_bed_shape {
$self->canvas->set_bed_shape($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; 1;

View file

@ -139,19 +139,19 @@ public:
const Points& copies() const { return this->_copies; } const Points& copies() const { return this->_copies; }
bool add_copy(const Pointf &point); bool add_copy(const Pointf &point);
bool delete_last_copy(); bool delete_last_copy();
bool delete_all_copies(); bool delete_all_copies() { return this->set_copies(Points()); }
bool set_copies(const Points &points); bool set_copies(const Points &points);
bool reload_model_instances(); bool reload_model_instances();
BoundingBox bounding_box() const { // since the object is aligned to origin, bounding box coincides with size
// since the object is aligned to origin, bounding box coincides with size BoundingBox bounding_box() const { return BoundingBox(Point(0,0), this->size); }
return BoundingBox(Point(0,0), this->size);
}
// adds region_id, too, if necessary // adds region_id, too, if necessary
void add_region_volume(int region_id, int volume_id); void add_region_volume(int region_id, int volume_id) { region_volumes[region_id].push_back(volume_id); }
// This is the *total* layer count (including support layers)
size_t total_layer_count() const; // this value is not supposed to be compared with Layer::id
size_t layer_count() const; // since they have different semantics.
size_t total_layer_count() const { return this->layer_count() + this->support_layer_count(); }
size_t layer_count() const { return this->layers.size(); }
void clear_layers(); void clear_layers();
Layer* get_layer(int idx) { return this->layers.at(idx); } Layer* get_layer(int idx) { return this->layers.at(idx); }
const Layer* get_layer(int idx) const { return this->layers.at(idx); } const Layer* get_layer(int idx) const { return this->layers.at(idx); }
@ -160,9 +160,9 @@ public:
Layer* add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z); Layer* add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z);
void delete_layer(int idx); void delete_layer(int idx);
size_t support_layer_count() const; size_t support_layer_count() const { return this->support_layers.size(); }
void clear_support_layers(); void clear_support_layers();
SupportLayer* get_support_layer(int idx); SupportLayer* get_support_layer(int idx) { return this->support_layers.at(idx); }
SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z); SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z);
void delete_support_layer(int idx); void delete_support_layer(int idx);

View file

@ -825,6 +825,8 @@ void _3DScene::_load_print_object_toolpaths(
bool color_by_tool() const { return tool_colors != nullptr; } bool color_by_tool() const { return tool_colors != nullptr; }
size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; } size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; }
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; } const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; }
int volume_idx(int extruder, int feature) const
{ return this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(extruder - 1, 0)) : feature; }
} ctxt; } ctxt;
ctxt.shifted_copies = &print_object->_shifted_copies; ctxt.shifted_copies = &print_object->_shifted_copies;
@ -890,41 +892,33 @@ void _3DScene::_load_print_object_toolpaths(
} }
for (const Point &copy: *ctxt.shifted_copies) { for (const Point &copy: *ctxt.shifted_copies) {
for (const LayerRegion *layerm : layer->regions) { for (const LayerRegion *layerm : layer->regions) {
if (ctxt.has_perimeters) { if (ctxt.has_perimeters)
int volume_idx = ctxt.color_by_tool() ? extrusionentity_to_verts(layerm->perimeters, float(layer->print_z), copy,
std::max<int>(layerm->region()->config.perimeter_extruder.value - 1, 0) : *vols[ctxt.volume_idx(layerm->region()->config.perimeter_extruder.value, 0)]);
0;
extrusionentity_to_verts(layerm->perimeters, float(layer->print_z), copy, *vols[volume_idx]);
}
if (ctxt.has_infill) { if (ctxt.has_infill) {
for (const ExtrusionEntity *ee : layerm->fills.entities) { for (const ExtrusionEntity *ee : layerm->fills.entities) {
// fill represents infill extrusions of a single island. // fill represents infill extrusions of a single island.
const auto *fill = dynamic_cast<const ExtrusionEntityCollection*>(ee); const auto *fill = dynamic_cast<const ExtrusionEntityCollection*>(ee);
if (fill->entities.empty()) if (! fill->entities.empty())
// This shouldn't happen but first_point() would fail. extrusionentity_to_verts(*fill, float(layer->print_z), copy,
continue; *vols[ctxt.volume_idx(
int volume_idx = ctxt.color_by_tool() ? is_solid_infill(fill->entities.front()->role()) ?
std::max<int>(0, layerm->region()->config.solid_infill_extruder :
(is_solid_infill(fill->entities.front()->role()) ? layerm->region()->config.infill_extruder,
layerm->region()->config.solid_infill_extruder : 1)]);
layerm->region()->config.infill_extruder) - 1) :
1;
extrusionentity_to_verts(*fill, float(layer->print_z), copy, *vols[volume_idx]);
} }
} }
} }
if (ctxt.has_support) { if (ctxt.has_support) {
const SupportLayer *support_layer = dynamic_cast<const SupportLayer*>(layer); const SupportLayer *support_layer = dynamic_cast<const SupportLayer*>(layer);
if (support_layer) { if (support_layer) {
for (const ExtrusionEntity *extrusion_entity : support_layer->support_fills.entities) { for (const ExtrusionEntity *extrusion_entity : support_layer->support_fills.entities)
int volume_idx = ctxt.color_by_tool() ? extrusionentity_to_verts(extrusion_entity, float(layer->print_z), copy,
std::max<int>(0, *vols[ctxt.volume_idx(
((extrusion_entity->role() == erSupportMaterial) ? (extrusion_entity->role() == erSupportMaterial) ?
support_layer->object()->config.support_material_extruder : support_layer->object()->config.support_material_extruder :
support_layer->object()->config.support_material_interface_extruder) - 1) : support_layer->object()->config.support_material_interface_extruder,
2; 2)]);
extrusionentity_to_verts(extrusion_entity, float(layer->print_z), copy, *vols[volume_idx]);
}
} }
} }
} }
@ -985,6 +979,8 @@ void _3DScene::_load_wipe_tower_toolpaths(
bool color_by_tool() const { return tool_colors != nullptr; } bool color_by_tool() const { return tool_colors != nullptr; }
size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; } size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; }
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; } const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; }
int volume_idx(int tool, int feature) const
{ return this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(tool, 0)) : feature; }
} ctxt; } ctxt;
ctxt.print = print; ctxt.print = print;
@ -1069,7 +1065,8 @@ void _3DScene::_load_wipe_tower_toolpaths(
lines.emplace_back(Point::new_scale(e_prev.pos.x, e_prev.pos.y), Point::new_scale(e.pos.x, e.pos.y)); lines.emplace_back(Point::new_scale(e_prev.pos.x, e_prev.pos.y), Point::new_scale(e.pos.x, e.pos.y));
widths.emplace_back(e.width); widths.emplace_back(e.width);
} }
thick_lines_to_verts(lines, widths, heights, lines.front().a == lines.back().b, extrusions.print_z, *vols[ctxt.color_by_tool() ? e.tool : 0]); thick_lines_to_verts(lines, widths, heights, lines.front().a == lines.back().b, extrusions.print_z,
*vols[ctxt.volume_idx(e.tool, 0)]);
} }
} }
} }

View file

@ -230,6 +230,7 @@ _constant()
%code%{ RETVAL = THIS->apply_config(*config); %}; %code%{ RETVAL = THIS->apply_config(*config); %};
bool has_infinite_skirt(); bool has_infinite_skirt();
bool has_skirt(); bool has_skirt();
std::vector<unsigned int> extruders() const;
std::string _validate() std::string _validate()
%code%{ RETVAL = THIS->validate(); %}; %code%{ RETVAL = THIS->validate(); %};
Clone<BoundingBox> bounding_box(); Clone<BoundingBox> bounding_box();