Refactoring: removed the non-idempotent init_extruders() step. Also, infill_extruder was not limited to the available number of extruders when slicing from the plater, and support material extruder was considered also when support material was disabled

This commit is contained in:
Alessandro Ranellucci 2015-03-06 09:56:58 +01:00
parent a3b843b24e
commit 722e94513c
16 changed files with 83 additions and 84 deletions

View File

@ -670,7 +670,7 @@ sub config {
} else { } else {
my $extruders_count = $self->{options_tabs}{printer}{extruders_count}; my $extruders_count = $self->{options_tabs}{printer}{extruders_count};
$config->set("${_}_extruder", min($config->get("${_}_extruder"), $extruders_count)) $config->set("${_}_extruder", min($config->get("${_}_extruder"), $extruders_count))
for qw(perimeter infill support_material support_material_interface); for qw(perimeter infill solid_infill support_material support_material_interface);
} }
return $config; return $config;

View File

@ -291,7 +291,7 @@ sub Render {
$brim_drawn = 1; $brim_drawn = 1;
} }
if ($self->print->step_done(STEP_SKIRT) if ($self->print->step_done(STEP_SKIRT)
&& ($self->print->config->skirt_height == -1 || $self->print->config->skirt_height > $layer->id) && ($self->print->has_infinite_skirt() || $self->print->config->skirt_height > $layer->id)
&& !$skirt_drawn) { && !$skirt_drawn) {
$self->color([0, 0, 0]); $self->color([0, 0, 0]);
$self->_draw(undef, $print_z, $_) for @{$self->print->skirt}; $self->_draw(undef, $print_z, $_) for @{$self->print->skirt};

View File

@ -102,9 +102,6 @@ sub export_svg {
my $self = shift; my $self = shift;
my %params = @_; my %params = @_;
# is this needed?
$self->init_extruders;
$_->slice for @{$self->objects}; $_->slice for @{$self->objects};
my $fh = $params{output_fh}; my $fh = $params{output_fh};
@ -209,8 +206,7 @@ sub make_skirt {
# checking whether we need to generate them # checking whether we need to generate them
$self->skirt->clear; $self->skirt->clear;
if (($self->config->skirts == 0 || $self->config->skirt_height == 0) if (!$self->has_skirt) {
&& (!$self->config->ooze_prevention || @{$self->extruders} == 1)) {
$self->set_step_done(STEP_SKIRT); $self->set_step_done(STEP_SKIRT);
return; return;
} }
@ -220,7 +216,7 @@ sub make_skirt {
# The skirt_height option from config is expressed in layers, but our # The skirt_height option from config is expressed in layers, but our
# object might have different layer heights, so we need to find the print_z # object might have different layer heights, so we need to find the print_z
# of the highest layer involved. # of the highest layer involved.
# Note that unless skirt_height == -1 (which means it's printed on all layers) # Note that unless has_infinite_skirt() == true
# the actual skirt might not reach this $skirt_height_z value since the print # the actual skirt might not reach this $skirt_height_z value since the print
# order of objects on each layer is not guaranteed and will not generally # order of objects on each layer is not guaranteed and will not generally
# include the thickest object first. It is just guaranteed that a skirt is # include the thickest object first. It is just guaranteed that a skirt is
@ -228,10 +224,9 @@ sub make_skirt {
# $skirt_height_z in this case is the highest possible skirt height for safety. # $skirt_height_z in this case is the highest possible skirt height for safety.
my $skirt_height_z = -1; my $skirt_height_z = -1;
foreach my $object (@{$self->objects}) { foreach my $object (@{$self->objects}) {
my $skirt_height = ($self->config->skirt_height == -1 || $self->config->ooze_prevention) my $skirt_height = $self->has_infinite_skirt
? scalar(@{$object->layers}) ? scalar(@{$object->layers})
: min($self->config->skirt_height, scalar(@{$object->layers})); : min($self->config->skirt_height, scalar(@{$object->layers}));
my $highest_layer = $object->get_layer($skirt_height - 1); my $highest_layer = $object->get_layer($skirt_height - 1);
$skirt_height_z = max($skirt_height_z, $highest_layer->print_z); $skirt_height_z = max($skirt_height_z, $highest_layer->print_z);
} }
@ -279,10 +274,13 @@ sub make_skirt {
my @extruders_e_per_mm = (); my @extruders_e_per_mm = ();
my $extruder_idx = 0; my $extruder_idx = 0;
my $skirts = $self->config->skirts;
$skirts ||= 1 if $self->has_infinite_skirt;
# draw outlines from outside to inside # draw outlines from outside to inside
# loop while we have less skirts than required or any extruder hasn't reached the min length if any # loop while we have less skirts than required or any extruder hasn't reached the min length if any
my $distance = scale max($self->config->skirt_distance, $self->config->brim_width); my $distance = scale max($self->config->skirt_distance, $self->config->brim_width);
for (my $i = $self->config->skirts; $i > 0; $i--) { for (my $i = $skirts; $i > 0; $i--) {
$distance += scale $spacing; $distance += scale $spacing;
my $loop = offset([$convex_hull], $distance, 1, JT_ROUND, scale(0.1))->[0]; my $loop = offset([$convex_hull], $distance, 1, JT_ROUND, scale(0.1))->[0];
$self->skirt->append(Slic3r::ExtrusionLoop->new_from_paths( $self->skirt->append(Slic3r::ExtrusionLoop->new_from_paths(

View File

@ -298,7 +298,7 @@ sub process_layer {
if (defined $self->_spiral_vase) { if (defined $self->_spiral_vase) {
$self->_spiral_vase->enable( $self->_spiral_vase->enable(
($layer->id > 0 || $self->print->config->brim_width == 0) ($layer->id > 0 || $self->print->config->brim_width == 0)
&& ($layer->id >= $self->print->config->skirt_height && $self->print->config->skirt_height != -1) && ($layer->id >= $self->print->config->skirt_height && !$self->print->has_infinite_skirt)
&& !defined(first { $_->config->bottom_solid_layers > $layer->id } @{$layer->regions}) && !defined(first { $_->config->bottom_solid_layers > $layer->id } @{$layer->regions})
&& !defined(first { @{$_->perimeters} > 1 } @{$layer->regions}) && !defined(first { @{$_->perimeters} > 1 } @{$layer->regions})
&& !defined(first { @{$_->fills} > 0 } @{$layer->regions}) && !defined(first { @{$_->fills} > 0 } @{$layer->regions})
@ -331,7 +331,7 @@ sub process_layer {
}) . "\n" if $self->print->config->layer_gcode; }) . "\n" if $self->print->config->layer_gcode;
# extrude skirt # extrude skirt
if (((values %{$self->_skirt_done}) < $self->print->config->skirt_height || $self->print->config->skirt_height == -1) if (((values %{$self->_skirt_done}) < $self->print->config->skirt_height || $self->print->has_infinite_skirt)
&& !$self->_skirt_done->{$layer->print_z} && !$self->_skirt_done->{$layer->print_z}
&& !$layer->isa('Slic3r::Layer::Support')) { && !$layer->isa('Slic3r::Layer::Support')) {
$self->_gcodegen->set_origin(Slic3r::Pointf->new(0,0)); $self->_gcodegen->set_origin(Slic3r::Pointf->new(0,0));
@ -339,7 +339,7 @@ sub process_layer {
my @extruder_ids = map { $_->id } @{$self->_gcodegen->writer->extruders}; my @extruder_ids = map { $_->id } @{$self->_gcodegen->writer->extruders};
$gcode .= $self->_gcodegen->set_extruder($extruder_ids[0]); $gcode .= $self->_gcodegen->set_extruder($extruder_ids[0]);
# skip skirt if we have a large brim # skip skirt if we have a large brim
if ($layer->id < $self->print->config->skirt_height || $self->print->config->skirt_height == -1) { if ($layer->id < $self->print->config->skirt_height || $self->print->has_infinite_skirt) {
my $skirt_flow = $self->print->skirt_flow; my $skirt_flow = $self->print->skirt_flow;
# distribute skirt loops across all extruders # distribute skirt loops across all extruders

View File

@ -344,7 +344,6 @@ sub make_perimeters {
my $self = shift; my $self = shift;
# prerequisites # prerequisites
$self->print->init_extruders;
$self->slice; $self->slice;
return if $self->step_done(STEP_PERIMETERS); return if $self->step_done(STEP_PERIMETERS);
@ -532,7 +531,6 @@ sub generate_support_material {
my $self = shift; my $self = shift;
# prerequisites # prerequisites
$self->print->init_extruders;
$self->slice; $self->slice;
return if $self->step_done(STEP_SUPPORTMATERIAL); return if $self->step_done(STEP_SUPPORTMATERIAL);

View File

@ -4,7 +4,7 @@ use warnings;
require Exporter; require Exporter;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT_OK = qw(STEP_INIT_EXTRUDERS STEP_SLICE STEP_PERIMETERS STEP_PREPARE_INFILL our @EXPORT_OK = qw(STEP_SLICE STEP_PERIMETERS STEP_PREPARE_INFILL
STEP_INFILL STEP_SUPPORTMATERIAL STEP_SKIRT STEP_BRIM); STEP_INFILL STEP_SUPPORTMATERIAL STEP_SKIRT STEP_BRIM);
our %EXPORT_TAGS = (steps => \@EXPORT_OK); our %EXPORT_TAGS = (steps => \@EXPORT_OK);

View File

@ -124,7 +124,6 @@ if (0) {
# copy of Print::export_gcode() up to the point # copy of Print::export_gcode() up to the point
# after fill surfaces are combined # after fill surfaces are combined
$self->init_extruders;
$_->slice for @{$self->objects}; $_->slice for @{$self->objects};
$_->make_perimeters for @{$self->objects}; $_->make_perimeters for @{$self->objects};
$_->detect_surfaces_type for @{$self->objects}; $_->detect_surfaces_type for @{$self->objects};

View File

@ -20,7 +20,6 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
{ {
my $print = Slic3r::Print->new; my $print = Slic3r::Print->new;
$print->init_extruders;
my $filler = Slic3r::Fill::Rectilinear->new( my $filler = Slic3r::Fill::Rectilinear->new(
print => $print, print => $print,
bounding_box => Slic3r::Geometry::BoundingBox->new_from_points([ Slic3r::Point->new(0, 0), Slic3r::Point->new(10, 10) ]), bounding_box => Slic3r::Geometry::BoundingBox->new_from_points([ Slic3r::Point->new(0, 0), Slic3r::Point->new(10, 10) ]),

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,6 @@ use Slic3r::Test;
my $test = sub { my $test = sub {
my $print = Slic3r::Test::init_print('20mm_cube', config => $config); my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
$print->print->init_extruders;
my $flow = $print->print->objects->[0]->support_material_flow; my $flow = $print->print->objects->[0]->support_material_flow;
my $support = Slic3r::Print::SupportMaterial->new( my $support = Slic3r::Print::SupportMaterial->new(
object_config => $print->print->objects->[0]->config, object_config => $print->print->objects->[0]->config,

View File

@ -166,13 +166,14 @@ Print::invalidate_state_by_config_options(const std::vector<t_config_option_key>
if (*opt_key == "skirts" if (*opt_key == "skirts"
|| *opt_key == "skirt_height" || *opt_key == "skirt_height"
|| *opt_key == "skirt_distance" || *opt_key == "skirt_distance"
|| *opt_key == "min_skirt_length") { || *opt_key == "min_skirt_length"
|| *opt_key == "ooze_prevention") {
steps.insert(psSkirt); steps.insert(psSkirt);
} else if (*opt_key == "brim_width") { } else if (*opt_key == "brim_width") {
steps.insert(psBrim); steps.insert(psBrim);
steps.insert(psSkirt); steps.insert(psSkirt);
} else if (*opt_key == "nozzle_diameter") { } else if (*opt_key == "nozzle_diameter") {
steps.insert(psInitExtruders); osteps.insert(posSlice);
} else if (*opt_key == "avoid_crossing_perimeters" } else if (*opt_key == "avoid_crossing_perimeters"
|| *opt_key == "bed_shape" || *opt_key == "bed_shape"
|| *opt_key == "bed_temperature" || *opt_key == "bed_temperature"
@ -266,11 +267,6 @@ Print::invalidate_step(PrintStep step)
// propagate to dependent steps // propagate to dependent steps
if (step == psSkirt) { if (step == psSkirt) {
this->invalidate_step(psBrim); this->invalidate_step(psBrim);
} else if (step == psInitExtruders) {
FOREACH_OBJECT(this, object) {
(*object)->invalidate_step(posPerimeters);
(*object)->invalidate_step(posSupportMaterial);
}
} }
return invalidated; return invalidated;
@ -314,9 +310,11 @@ Print::extruders() const
extruders.insert((*region)->config.solid_infill_extruder - 1); extruders.insert((*region)->config.solid_infill_extruder - 1);
} }
FOREACH_OBJECT(this, object) { FOREACH_OBJECT(this, object) {
if ((*object)->has_support_material()) {
extruders.insert((*object)->config.support_material_extruder - 1); extruders.insert((*object)->config.support_material_extruder - 1);
extruders.insert((*object)->config.support_material_interface_extruder - 1); extruders.insert((*object)->config.support_material_interface_extruder - 1);
} }
}
return extruders; return extruders;
} }
@ -534,20 +532,16 @@ Print::apply_config(DynamicPrintConfig config)
return invalidated; return invalidated;
} }
void bool Print::has_infinite_skirt() const
Print::init_extruders()
{ {
if (this->state.is_done(psInitExtruders)) return; return (this->config.skirt_height == -1 && this->config.skirts > 0)
this->state.set_done(psInitExtruders); || (this->config.ooze_prevention && this->extruders().size() > 1);
// enforce tall skirt if using ooze_prevention
// FIXME: this is not idempotent (i.e. switching ooze_prevention off will not revert skirt settings)
if (this->config.ooze_prevention && this->extruders().size() > 1) {
this->config.skirt_height.value = -1;
if (this->config.skirts == 0) this->config.skirts.value = 1;
} }
this->state.set_done(psInitExtruders); bool Print::has_skirt() const
{
return (this->config.skirt_height > 0 && this->config.skirts > 0)
|| this->has_infinite_skirt();
} }
void void
@ -682,13 +676,15 @@ Print::total_bounding_box() const
Flow brim_flow = this->brim_flow(); Flow brim_flow = this->brim_flow();
extra = std::max(extra, this->config.brim_width.value + brim_flow.width/2); extra = std::max(extra, this->config.brim_width.value + brim_flow.width/2);
} }
if (this->config.skirts.value > 0) { if (this->has_skirt()) {
int skirts = this->config.skirts.value;
if (skirts == 0 && this->has_infinite_skirt()) skirts = 1;
Flow skirt_flow = this->skirt_flow(); Flow skirt_flow = this->skirt_flow();
extra = std::max( extra = std::max(
extra, extra,
this->config.brim_width.value this->config.brim_width.value
+ this->config.skirt_distance.value + this->config.skirt_distance.value
+ this->config.skirts.value * skirt_flow.spacing() + skirts * skirt_flow.spacing()
+ skirt_flow.width/2 + skirt_flow.width/2
); );
} }
@ -773,9 +769,7 @@ bool
Print::has_support_material() const Print::has_support_material() const
{ {
FOREACH_OBJECT(this, object) { FOREACH_OBJECT(this, object) {
PrintObjectConfig &config = (*object)->config; if ((*object)->has_support_material()) return true;
if (config.support_material || config.raft_layers > 0 || config.support_material_enforce_layers > 0)
return true;
} }
return false; return false;
} }

View File

@ -22,7 +22,7 @@ class ModelObject;
enum PrintStep { enum PrintStep {
psInitExtruders, psSkirt, psBrim, psSkirt, psBrim,
}; };
enum PrintObjectStep { enum PrintObjectStep {
posSlice, posPerimeters, posPrepareInfill, posSlice, posPerimeters, posPrepareInfill,
@ -134,6 +134,7 @@ class PrintObject
bool invalidate_step(PrintObjectStep step); bool invalidate_step(PrintObjectStep step);
bool invalidate_all_steps(); bool invalidate_all_steps();
bool has_support_material() const;
void bridge_over_infill(); void bridge_over_infill();
private: private:
@ -188,7 +189,8 @@ class Print
void add_model_object(ModelObject* model_object, int idx = -1); void add_model_object(ModelObject* model_object, int idx = -1);
bool apply_config(DynamicPrintConfig config); bool apply_config(DynamicPrintConfig config);
void init_extruders(); bool has_infinite_skirt() const;
bool has_skirt() const;
void validate() const; void validate() const;
BoundingBox bounding_box() const; BoundingBox bounding_box() const;
BoundingBox total_bounding_box() const; BoundingBox total_bounding_box() const;

View File

@ -1011,6 +1011,40 @@ PrintConfigDef::build_def() {
t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def(); t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def();
void
DynamicPrintConfig::normalize() {
if (this->has("extruder")) {
int extruder = this->option("extruder")->getInt();
this->erase("extruder");
if (extruder != 0) {
if (!this->has("infill_extruder"))
this->option("infill_extruder", true)->setInt(extruder);
if (!this->has("perimeter_extruder"))
this->option("perimeter_extruder", true)->setInt(extruder);
if (!this->has("support_material_extruder"))
this->option("support_material_extruder", true)->setInt(extruder);
if (!this->has("support_material_interface_extruder"))
this->option("support_material_interface_extruder", true)->setInt(extruder);
}
}
if (!this->has("solid_infill_extruder") && this->has("infill_extruder"))
this->option("solid_infill_extruder", true)->setInt(this->option("infill_extruder")->getInt());
if (this->has("spiral_vase") && this->opt<ConfigOptionBool>("spiral_vase", true)->value) {
{
// this should be actually done only on the spiral layers instead of all
ConfigOptionBools* opt = this->opt<ConfigOptionBools>("retract_layer_change", true);
opt->values.assign(opt->values.size(), false); // set all values to false
}
{
this->opt<ConfigOptionInt>("perimeters", true)->value = 1;
this->opt<ConfigOptionInt>("top_solid_layers", true)->value = 0;
this->opt<ConfigOptionPercent>("fill_density", true)->value = 0;
}
}
}
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(DynamicPrintConfig, "Config"); REGISTER_CLASS(DynamicPrintConfig, "Config");
REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject"); REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject");

View File

@ -79,38 +79,7 @@ class DynamicPrintConfig : public DynamicConfig
this->def = &PrintConfigDef::def; this->def = &PrintConfigDef::def;
}; };
void normalize() { void normalize();
if (this->has("extruder")) {
int extruder = this->option("extruder")->getInt();
this->erase("extruder");
if (extruder != 0) {
if (!this->has("infill_extruder"))
this->option("infill_extruder", true)->setInt(extruder);
if (!this->has("perimeter_extruder"))
this->option("perimeter_extruder", true)->setInt(extruder);
if (!this->has("support_material_extruder"))
this->option("support_material_extruder", true)->setInt(extruder);
if (!this->has("support_material_interface_extruder"))
this->option("support_material_interface_extruder", true)->setInt(extruder);
}
}
if (!this->has("solid_infill_extruder") && this->has("infill_extruder"))
this->option("solid_infill_extruder", true)->setInt(this->option("infill_extruder")->getInt());
if (this->has("spiral_vase") && this->opt<ConfigOptionBool>("spiral_vase", true)->value) {
{
// this should be actually done only on the spiral layers instead of all
ConfigOptionBools* opt = this->opt<ConfigOptionBools>("retract_layer_change", true);
opt->values.assign(opt->values.size(), false); // set all values to false
}
{
this->opt<ConfigOptionInt>("perimeters", true)->value = 1;
this->opt<ConfigOptionInt>("top_solid_layers", true)->value = 0;
this->opt<ConfigOptionPercent>("fill_density", true)->value = 0;
}
}
};
}; };
class StaticPrintConfig : public virtual StaticConfig class StaticPrintConfig : public virtual StaticConfig

View File

@ -333,6 +333,14 @@ PrintObject::invalidate_all_steps()
return invalidated; return invalidated;
} }
bool
PrintObject::has_support_material() const
{
return this->config.support_material
|| this->config.raft_layers > 0
|| this->config.support_material_enforce_layers > 0;
}
void void
PrintObject::bridge_over_infill() PrintObject::bridge_over_infill()
{ {

View File

@ -12,7 +12,6 @@
IV IV
_constant() _constant()
ALIAS: ALIAS:
STEP_INIT_EXTRUDERS = psInitExtruders
STEP_SLICE = posSlice STEP_SLICE = posSlice
STEP_PERIMETERS = posPerimeters STEP_PERIMETERS = posPerimeters
STEP_PREPARE_INFILL = posPrepareInfill STEP_PREPARE_INFILL = posPrepareInfill
@ -177,7 +176,8 @@ _constant()
void add_model_object(ModelObject* model_object, int idx = -1); void add_model_object(ModelObject* model_object, int idx = -1);
bool apply_config(DynamicPrintConfig* config) bool apply_config(DynamicPrintConfig* config)
%code%{ RETVAL = THIS->apply_config(*config); %}; %code%{ RETVAL = THIS->apply_config(*config); %};
void init_extruders(); bool has_infinite_skirt();
bool has_skirt();
void validate() void validate()
%code%{ %code%{
try { try {