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

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

View file

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

View file

@ -79,38 +79,7 @@ class DynamicPrintConfig : public DynamicConfig
this->def = &PrintConfigDef::def;
};
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;
}
}
};
void normalize();
};
class StaticPrintConfig : public virtual StaticConfig

View file

@ -333,6 +333,14 @@ PrintObject::invalidate_all_steps()
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
PrintObject::bridge_over_infill()
{

View file

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