mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 20:26:02 +08:00
Refactored the config/step invalidation code. Now we can take values into account in order to reduce unneeded recalculation
This commit is contained in:
parent
d3a91129bb
commit
85f84aa7dc
@ -242,8 +242,8 @@ ConfigDef::merge(const ConfigDef &other)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ConfigBase::has(const t_config_option_key &opt_key) {
|
ConfigBase::has(const t_config_option_key &opt_key) const {
|
||||||
return (this->option(opt_key, false) != NULL);
|
return this->option(opt_key) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -272,21 +272,18 @@ ConfigBase::apply_only(const ConfigBase &other, const t_config_option_keys &opt_
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ConfigBase::equals(ConfigBase &other) {
|
ConfigBase::equals(const ConfigBase &other) const {
|
||||||
return this->diff(other).empty();
|
return this->diff(other).empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this will *ignore* options not present in both configs
|
// this will *ignore* options not present in both configs
|
||||||
t_config_option_keys
|
t_config_option_keys
|
||||||
ConfigBase::diff(ConfigBase &other) {
|
ConfigBase::diff(const ConfigBase &other) const {
|
||||||
t_config_option_keys diff;
|
t_config_option_keys diff;
|
||||||
|
|
||||||
t_config_option_keys my_keys = this->keys();
|
for (const t_config_option_key &opt_key : this->keys())
|
||||||
for (t_config_option_keys::const_iterator opt_key = my_keys.begin(); opt_key != my_keys.end(); ++opt_key) {
|
if (other.has(opt_key) && other.serialize(opt_key) != this->serialize(opt_key))
|
||||||
if (other.has(*opt_key) && other.serialize(*opt_key) != this->serialize(*opt_key)) {
|
diff.push_back(opt_key);
|
||||||
diff.push_back(*opt_key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
@ -391,6 +388,25 @@ ConfigBase::option(const t_config_option_key &opt_key, bool create) {
|
|||||||
return this->optptr(opt_key, create);
|
return this->optptr(opt_key, create);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
template<class T>
|
||||||
|
T*
|
||||||
|
ConfigBase::opt(const t_config_option_key &opt_key, bool create) {
|
||||||
|
return dynamic_cast<T*>(this->option(opt_key, create));
|
||||||
|
}
|
||||||
|
template ConfigOptionInt* ConfigBase::opt<ConfigOptionInt>(const t_config_option_key &opt_key, bool create);
|
||||||
|
template ConfigOptionBool* ConfigBase::opt<ConfigOptionBool>(const t_config_option_key &opt_key, bool create);
|
||||||
|
template ConfigOptionBools* ConfigBase::opt<ConfigOptionBools>(const t_config_option_key &opt_key, bool create);
|
||||||
|
template ConfigOptionPercent* ConfigBase::opt<ConfigOptionPercent>(const t_config_option_key &opt_key, bool create);
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
const T*
|
||||||
|
ConfigBase::opt(const t_config_option_key &opt_key) const {
|
||||||
|
return dynamic_cast<const T*>(this->option(opt_key));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
ConfigBase::load(const std::string &file)
|
ConfigBase::load(const std::string &file)
|
||||||
{
|
{
|
||||||
@ -504,16 +520,6 @@ DynamicConfig::optptr(const t_config_option_key &opt_key, bool create) {
|
|||||||
return this->options[opt_key];
|
return this->options[opt_key];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
|
||||||
T*
|
|
||||||
DynamicConfig::opt(const t_config_option_key &opt_key, bool create) {
|
|
||||||
return dynamic_cast<T*>(this->option(opt_key, create));
|
|
||||||
}
|
|
||||||
template ConfigOptionInt* DynamicConfig::opt<ConfigOptionInt>(const t_config_option_key &opt_key, bool create);
|
|
||||||
template ConfigOptionBool* DynamicConfig::opt<ConfigOptionBool>(const t_config_option_key &opt_key, bool create);
|
|
||||||
template ConfigOptionBools* DynamicConfig::opt<ConfigOptionBools>(const t_config_option_key &opt_key, bool create);
|
|
||||||
template ConfigOptionPercent* DynamicConfig::opt<ConfigOptionPercent>(const t_config_option_key &opt_key, bool create);
|
|
||||||
|
|
||||||
t_config_option_keys
|
t_config_option_keys
|
||||||
DynamicConfig::keys() const {
|
DynamicConfig::keys() const {
|
||||||
t_config_option_keys keys;
|
t_config_option_keys keys;
|
||||||
|
@ -644,15 +644,21 @@ class ConfigBase
|
|||||||
ConfigBase() : def(NULL) {};
|
ConfigBase() : def(NULL) {};
|
||||||
ConfigBase(const ConfigDef* def) : def(def) {};
|
ConfigBase(const ConfigDef* def) : def(def) {};
|
||||||
virtual ~ConfigBase() {};
|
virtual ~ConfigBase() {};
|
||||||
bool has(const t_config_option_key &opt_key);
|
bool has(const t_config_option_key &opt_key) const;
|
||||||
const ConfigOption* option(const t_config_option_key &opt_key) const;
|
const ConfigOption* option(const t_config_option_key &opt_key) const;
|
||||||
ConfigOption* option(const t_config_option_key &opt_key, bool create = false);
|
ConfigOption* option(const t_config_option_key &opt_key, bool create = false);
|
||||||
|
template<class T> T* opt(const t_config_option_key &opt_key, bool create = false) {
|
||||||
|
return dynamic_cast<T*>(this->option(opt_key, create));
|
||||||
|
};
|
||||||
|
template<class T> const T* opt(const t_config_option_key &opt_key) const {
|
||||||
|
return dynamic_cast<const T*>(this->option(opt_key));
|
||||||
|
};
|
||||||
virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) = 0;
|
virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) = 0;
|
||||||
virtual t_config_option_keys keys() const = 0;
|
virtual t_config_option_keys keys() const = 0;
|
||||||
void apply(const ConfigBase &other, bool ignore_nonexistent = false);
|
void apply(const ConfigBase &other, bool ignore_nonexistent = false);
|
||||||
void apply_only(const ConfigBase &other, const t_config_option_keys &opt_keys, bool ignore_nonexistent = false);
|
void apply_only(const ConfigBase &other, const t_config_option_keys &opt_keys, bool ignore_nonexistent = false);
|
||||||
bool equals(ConfigBase &other);
|
bool equals(const ConfigBase &other) const;
|
||||||
t_config_option_keys diff(ConfigBase &other);
|
t_config_option_keys diff(const ConfigBase &other) const;
|
||||||
std::string serialize(const t_config_option_key &opt_key) const;
|
std::string serialize(const t_config_option_key &opt_key) const;
|
||||||
virtual bool set_deserialize(t_config_option_key opt_key, std::string str, bool append = false);
|
virtual bool set_deserialize(t_config_option_key opt_key, std::string str, bool append = false);
|
||||||
double get_abs_value(const t_config_option_key &opt_key) const;
|
double get_abs_value(const t_config_option_key &opt_key) const;
|
||||||
@ -673,7 +679,6 @@ class DynamicConfig : public virtual ConfigBase
|
|||||||
DynamicConfig& operator= (DynamicConfig other);
|
DynamicConfig& operator= (DynamicConfig other);
|
||||||
void swap(DynamicConfig &other);
|
void swap(DynamicConfig &other);
|
||||||
virtual ~DynamicConfig();
|
virtual ~DynamicConfig();
|
||||||
template<class T> T* opt(const t_config_option_key &opt_key, bool create = false);
|
|
||||||
virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false);
|
virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false);
|
||||||
t_config_option_keys keys() const;
|
t_config_option_keys keys() const;
|
||||||
void erase(const t_config_option_key &opt_key);
|
void erase(const t_config_option_key &opt_key);
|
||||||
|
@ -147,92 +147,95 @@ Print::delete_region(size_t idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Print::invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys)
|
Print::invalidate_state_by_config(const PrintConfigBase &config)
|
||||||
{
|
{
|
||||||
|
const t_config_option_keys diff = this->config.diff(config);
|
||||||
|
|
||||||
std::set<PrintStep> steps;
|
std::set<PrintStep> steps;
|
||||||
std::set<PrintObjectStep> osteps;
|
std::set<PrintObjectStep> osteps;
|
||||||
|
bool all = false;
|
||||||
|
|
||||||
// this method only accepts PrintConfig option keys
|
// this method only accepts PrintConfig option keys
|
||||||
for (std::vector<t_config_option_key>::const_iterator opt_key = opt_keys.begin(); opt_key != opt_keys.end(); ++opt_key) {
|
for (const t_config_option_key &opt_key : diff) {
|
||||||
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") {
|
|| opt_key == "ooze_prevention") {
|
||||||
steps.insert(psSkirt);
|
steps.insert(psSkirt);
|
||||||
} else if (*opt_key == "brim_width"
|
} else if (opt_key == "brim_width"
|
||||||
|| *opt_key == "interior_brim_width"
|
|| opt_key == "interior_brim_width"
|
||||||
|| *opt_key == "brim_connections_width") {
|
|| opt_key == "brim_connections_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"
|
||||||
|| *opt_key == "resolution"
|
|| opt_key == "resolution"
|
||||||
|| *opt_key == "z_steps_per_mm") {
|
|| opt_key == "z_steps_per_mm") {
|
||||||
osteps.insert(posSlice);
|
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"
|
||||||
|| *opt_key == "bridge_acceleration"
|
|| opt_key == "bridge_acceleration"
|
||||||
|| *opt_key == "bridge_fan_speed"
|
|| opt_key == "bridge_fan_speed"
|
||||||
|| *opt_key == "complete_objects"
|
|| opt_key == "complete_objects"
|
||||||
|| *opt_key == "cooling"
|
|| opt_key == "cooling"
|
||||||
|| *opt_key == "default_acceleration"
|
|| opt_key == "default_acceleration"
|
||||||
|| *opt_key == "disable_fan_first_layers"
|
|| opt_key == "disable_fan_first_layers"
|
||||||
|| *opt_key == "duplicate_distance"
|
|| opt_key == "duplicate_distance"
|
||||||
|| *opt_key == "end_gcode"
|
|| opt_key == "end_gcode"
|
||||||
|| *opt_key == "extruder_clearance_height"
|
|| opt_key == "extruder_clearance_height"
|
||||||
|| *opt_key == "extruder_clearance_radius"
|
|| opt_key == "extruder_clearance_radius"
|
||||||
|| *opt_key == "extruder_offset"
|
|| opt_key == "extruder_offset"
|
||||||
|| *opt_key == "extrusion_axis"
|
|| opt_key == "extrusion_axis"
|
||||||
|| *opt_key == "extrusion_multiplier"
|
|| opt_key == "extrusion_multiplier"
|
||||||
|| *opt_key == "fan_always_on"
|
|| opt_key == "fan_always_on"
|
||||||
|| *opt_key == "fan_below_layer_time"
|
|| opt_key == "fan_below_layer_time"
|
||||||
|| *opt_key == "filament_colour"
|
|| opt_key == "filament_colour"
|
||||||
|| *opt_key == "filament_diameter"
|
|| opt_key == "filament_diameter"
|
||||||
|| *opt_key == "first_layer_acceleration"
|
|| opt_key == "first_layer_acceleration"
|
||||||
|| *opt_key == "first_layer_bed_temperature"
|
|| opt_key == "first_layer_bed_temperature"
|
||||||
|| *opt_key == "first_layer_speed"
|
|| opt_key == "first_layer_speed"
|
||||||
|| *opt_key == "first_layer_temperature"
|
|| opt_key == "first_layer_temperature"
|
||||||
|| *opt_key == "gcode_arcs"
|
|| opt_key == "gcode_arcs"
|
||||||
|| *opt_key == "gcode_comments"
|
|| opt_key == "gcode_comments"
|
||||||
|| *opt_key == "gcode_flavor"
|
|| opt_key == "gcode_flavor"
|
||||||
|| *opt_key == "infill_acceleration"
|
|| opt_key == "infill_acceleration"
|
||||||
|| *opt_key == "infill_first"
|
|| opt_key == "infill_first"
|
||||||
|| *opt_key == "layer_gcode"
|
|| opt_key == "layer_gcode"
|
||||||
|| *opt_key == "min_fan_speed"
|
|| opt_key == "min_fan_speed"
|
||||||
|| *opt_key == "max_fan_speed"
|
|| opt_key == "max_fan_speed"
|
||||||
|| *opt_key == "min_print_speed"
|
|| opt_key == "min_print_speed"
|
||||||
|| *opt_key == "notes"
|
|| opt_key == "notes"
|
||||||
|| *opt_key == "only_retract_when_crossing_perimeters"
|
|| opt_key == "only_retract_when_crossing_perimeters"
|
||||||
|| *opt_key == "output_filename_format"
|
|| opt_key == "output_filename_format"
|
||||||
|| *opt_key == "perimeter_acceleration"
|
|| opt_key == "perimeter_acceleration"
|
||||||
|| *opt_key == "post_process"
|
|| opt_key == "post_process"
|
||||||
|| *opt_key == "pressure_advance"
|
|| opt_key == "pressure_advance"
|
||||||
|| *opt_key == "retract_before_travel"
|
|| opt_key == "retract_before_travel"
|
||||||
|| *opt_key == "retract_layer_change"
|
|| opt_key == "retract_layer_change"
|
||||||
|| *opt_key == "retract_length"
|
|| opt_key == "retract_length"
|
||||||
|| *opt_key == "retract_length_toolchange"
|
|| opt_key == "retract_length_toolchange"
|
||||||
|| *opt_key == "retract_lift"
|
|| opt_key == "retract_lift"
|
||||||
|| *opt_key == "retract_lift_above"
|
|| opt_key == "retract_lift_above"
|
||||||
|| *opt_key == "retract_lift_below"
|
|| opt_key == "retract_lift_below"
|
||||||
|| *opt_key == "retract_restart_extra"
|
|| opt_key == "retract_restart_extra"
|
||||||
|| *opt_key == "retract_restart_extra_toolchange"
|
|| opt_key == "retract_restart_extra_toolchange"
|
||||||
|| *opt_key == "retract_speed"
|
|| opt_key == "retract_speed"
|
||||||
|| *opt_key == "slowdown_below_layer_time"
|
|| opt_key == "slowdown_below_layer_time"
|
||||||
|| *opt_key == "spiral_vase"
|
|| opt_key == "spiral_vase"
|
||||||
|| *opt_key == "standby_temperature_delta"
|
|| opt_key == "standby_temperature_delta"
|
||||||
|| *opt_key == "start_gcode"
|
|| opt_key == "start_gcode"
|
||||||
|| *opt_key == "temperature"
|
|| opt_key == "temperature"
|
||||||
|| *opt_key == "threads"
|
|| opt_key == "threads"
|
||||||
|| *opt_key == "toolchange_gcode"
|
|| opt_key == "toolchange_gcode"
|
||||||
|| *opt_key == "travel_speed"
|
|| opt_key == "travel_speed"
|
||||||
|| *opt_key == "use_firmware_retraction"
|
|| opt_key == "use_firmware_retraction"
|
||||||
|| *opt_key == "use_relative_e_distances"
|
|| opt_key == "use_relative_e_distances"
|
||||||
|| *opt_key == "vibration_limit"
|
|| opt_key == "vibration_limit"
|
||||||
|| *opt_key == "wipe"
|
|| opt_key == "wipe"
|
||||||
|| *opt_key == "z_offset") {
|
|| opt_key == "z_offset") {
|
||||||
// these options only affect G-code export, so nothing to invalidate
|
// these options only affect G-code export, so nothing to invalidate
|
||||||
} else if (*opt_key == "first_layer_extrusion_width") {
|
} else if (opt_key == "first_layer_extrusion_width") {
|
||||||
osteps.insert(posPerimeters);
|
osteps.insert(posPerimeters);
|
||||||
osteps.insert(posInfill);
|
osteps.insert(posInfill);
|
||||||
osteps.insert(posSupportMaterial);
|
osteps.insert(posSupportMaterial);
|
||||||
@ -240,18 +243,31 @@ Print::invalidate_state_by_config_options(const std::vector<t_config_option_key>
|
|||||||
steps.insert(psBrim);
|
steps.insert(psBrim);
|
||||||
} else {
|
} else {
|
||||||
// for legacy, if we can't handle this option let's invalidate all steps
|
// for legacy, if we can't handle this option let's invalidate all steps
|
||||||
return this->invalidate_all_steps();
|
all = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!diff.empty())
|
||||||
|
this->config.apply(config, true);
|
||||||
|
|
||||||
bool invalidated = false;
|
bool invalidated = false;
|
||||||
for (std::set<PrintStep>::const_iterator step = steps.begin(); step != steps.end(); ++step) {
|
if (all) {
|
||||||
if (this->invalidate_step(*step)) invalidated = true;
|
if (this->invalidate_all_steps())
|
||||||
}
|
invalidated = true;
|
||||||
for (std::set<PrintObjectStep>::const_iterator ostep = osteps.begin(); ostep != osteps.end(); ++ostep) {
|
|
||||||
FOREACH_OBJECT(this, object) {
|
for (PrintObject* object : this->objects)
|
||||||
if ((*object)->invalidate_step(*ostep)) invalidated = true;
|
if (object->invalidate_all_steps())
|
||||||
}
|
invalidated = true;
|
||||||
|
} else {
|
||||||
|
for (const PrintStep &step : steps)
|
||||||
|
if (this->invalidate_step(step))
|
||||||
|
invalidated = true;
|
||||||
|
|
||||||
|
for (const PrintObjectStep &ostep : osteps)
|
||||||
|
for (PrintObject* object : this->objects)
|
||||||
|
if (object->invalidate_step(ostep))
|
||||||
|
invalidated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return invalidated;
|
return invalidated;
|
||||||
@ -481,20 +497,12 @@ Print::apply_config(DynamicPrintConfig config)
|
|||||||
// apply variables to placeholder parser
|
// apply variables to placeholder parser
|
||||||
this->placeholder_parser.apply_config(config);
|
this->placeholder_parser.apply_config(config);
|
||||||
|
|
||||||
bool invalidated = false;
|
|
||||||
|
|
||||||
// handle changes to print config
|
// handle changes to print config
|
||||||
t_config_option_keys print_diff = this->config.diff(config);
|
bool invalidated = this->invalidate_state_by_config(config);
|
||||||
if (!print_diff.empty()) {
|
|
||||||
this->config.apply(config, true);
|
|
||||||
|
|
||||||
if (this->invalidate_state_by_config_options(print_diff))
|
|
||||||
invalidated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle changes to object config defaults
|
// handle changes to object config defaults
|
||||||
this->default_object_config.apply(config, true);
|
this->default_object_config.apply(config, true);
|
||||||
FOREACH_OBJECT(this, obj_ptr) {
|
for (PrintObject* object : this->objects) {
|
||||||
// we don't assume that config contains a full ObjectConfig,
|
// we don't assume that config contains a full ObjectConfig,
|
||||||
// so we base it on the current print-wise default
|
// so we base it on the current print-wise default
|
||||||
PrintObjectConfig new_config = this->default_object_config;
|
PrintObjectConfig new_config = this->default_object_config;
|
||||||
@ -502,20 +510,15 @@ Print::apply_config(DynamicPrintConfig config)
|
|||||||
|
|
||||||
// we override the new config with object-specific options
|
// we override the new config with object-specific options
|
||||||
{
|
{
|
||||||
DynamicPrintConfig model_object_config = (*obj_ptr)->model_object()->config;
|
DynamicPrintConfig model_object_config = object->model_object()->config;
|
||||||
model_object_config.normalize();
|
model_object_config.normalize();
|
||||||
new_config.apply(model_object_config, true);
|
new_config.apply(model_object_config, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether the new config is different from the current one
|
// check whether the new config is different from the current one
|
||||||
t_config_option_keys diff = (*obj_ptr)->config.diff(new_config);
|
if (object->invalidate_state_by_config(new_config))
|
||||||
if (!diff.empty()) {
|
|
||||||
(*obj_ptr)->config.apply(new_config, true);
|
|
||||||
|
|
||||||
if ((*obj_ptr)->invalidate_state_by_config_options(diff))
|
|
||||||
invalidated = true;
|
invalidated = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// handle changes to regions config defaults
|
// handle changes to regions config defaults
|
||||||
this->default_region_config.apply(config, true);
|
this->default_region_config.apply(config, true);
|
||||||
@ -563,16 +566,10 @@ Print::apply_config(DynamicPrintConfig config)
|
|||||||
// if we're here and the new region config is different from the old
|
// if we're here and the new region config is different from the old
|
||||||
// one, we need to apply the new config and invalidate all objects
|
// one, we need to apply the new config and invalidate all objects
|
||||||
// (possible optimization: only invalidate objects using this region)
|
// (possible optimization: only invalidate objects using this region)
|
||||||
t_config_option_keys region_config_diff = region->config.diff(new_config);
|
if (region->invalidate_state_by_config(new_config))
|
||||||
if (!region_config_diff.empty()) {
|
|
||||||
region->config.apply(new_config);
|
|
||||||
FOREACH_OBJECT(this, o) {
|
|
||||||
if ((*o)->invalidate_state_by_config_options(region_config_diff))
|
|
||||||
invalidated = true;
|
invalidated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
other_region_configs.insert(other_region_configs.end(), this_region_configs.begin(), this_region_configs.end());
|
other_region_configs.insert(other_region_configs.end(), this_region_configs.begin(), this_region_configs.end());
|
||||||
|
|
||||||
NEXT_REGION:
|
NEXT_REGION:
|
||||||
|
@ -55,6 +55,7 @@ class PrintRegion
|
|||||||
|
|
||||||
Print* print();
|
Print* print();
|
||||||
Flow flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, const PrintObject &object) const;
|
Flow flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, const PrintObject &object) const;
|
||||||
|
bool invalidate_state_by_config(const PrintConfigBase &config);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Print* _print;
|
Print* _print;
|
||||||
@ -132,7 +133,7 @@ class PrintObject
|
|||||||
void delete_support_layer(int idx);
|
void delete_support_layer(int idx);
|
||||||
|
|
||||||
// methods for handling state
|
// methods for handling state
|
||||||
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
bool invalidate_state_by_config(const PrintConfigBase &config);
|
||||||
bool invalidate_step(PrintObjectStep step);
|
bool invalidate_step(PrintObjectStep step);
|
||||||
bool invalidate_all_steps();
|
bool invalidate_all_steps();
|
||||||
|
|
||||||
@ -196,7 +197,7 @@ class Print
|
|||||||
PrintRegion* add_region();
|
PrintRegion* add_region();
|
||||||
|
|
||||||
// methods for handling state
|
// methods for handling state
|
||||||
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
bool invalidate_state_by_config(const PrintConfigBase &config);
|
||||||
bool invalidate_step(PrintStep step);
|
bool invalidate_step(PrintStep step);
|
||||||
bool invalidate_all_steps();
|
bool invalidate_all_steps();
|
||||||
bool step_done(PrintObjectStep step) const;
|
bool step_done(PrintObjectStep step) const;
|
||||||
|
@ -212,90 +212,63 @@ PrintObject::delete_support_layer(int idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PrintObject::invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys)
|
PrintObject::invalidate_state_by_config(const PrintConfigBase &config)
|
||||||
{
|
{
|
||||||
|
const t_config_option_keys diff = this->config.diff(config);
|
||||||
|
|
||||||
std::set<PrintObjectStep> steps;
|
std::set<PrintObjectStep> steps;
|
||||||
|
bool all = false;
|
||||||
|
|
||||||
// this method only accepts PrintObjectConfig and PrintRegionConfig option keys
|
// this method only accepts PrintObjectConfig and PrintRegionConfig option keys
|
||||||
for (std::vector<t_config_option_key>::const_iterator opt_key = opt_keys.begin(); opt_key != opt_keys.end(); ++opt_key) {
|
for (const t_config_option_key &opt_key : diff) {
|
||||||
if (*opt_key == "perimeters"
|
if (opt_key == "layer_height"
|
||||||
|| *opt_key == "extra_perimeters"
|
|| opt_key == "first_layer_height"
|
||||||
|| *opt_key == "gap_fill_speed"
|
|| opt_key == "xy_size_compensation"
|
||||||
|| *opt_key == "overhangs"
|
|| opt_key == "raft_layers") {
|
||||||
|| *opt_key == "first_layer_extrusion_width"
|
steps.insert(posSlice);
|
||||||
|| *opt_key == "perimeter_extrusion_width"
|
} else if (opt_key == "support_material_contact_distance") {
|
||||||
|| *opt_key == "thin_walls"
|
|
||||||
|| *opt_key == "external_perimeters_first") {
|
|
||||||
steps.insert(posPerimeters);
|
|
||||||
} else if (*opt_key == "layer_height"
|
|
||||||
|| *opt_key == "first_layer_height"
|
|
||||||
|| *opt_key == "xy_size_compensation"
|
|
||||||
|| *opt_key == "raft_layers") {
|
|
||||||
steps.insert(posSlice);
|
steps.insert(posSlice);
|
||||||
} else if (*opt_key == "support_material"
|
|
||||||
|| *opt_key == "support_material_angle"
|
|
||||||
|| *opt_key == "support_material_extruder"
|
|
||||||
|| *opt_key == "support_material_extrusion_width"
|
|
||||||
|| *opt_key == "support_material_interface_layers"
|
|
||||||
|| *opt_key == "support_material_interface_extruder"
|
|
||||||
|| *opt_key == "support_material_interface_spacing"
|
|
||||||
|| *opt_key == "support_material_interface_speed"
|
|
||||||
|| *opt_key == "support_material_buildplate_only"
|
|
||||||
|| *opt_key == "support_material_pattern"
|
|
||||||
|| *opt_key == "support_material_spacing"
|
|
||||||
|| *opt_key == "support_material_threshold"
|
|
||||||
|| *opt_key == "dont_support_bridges"
|
|
||||||
|| *opt_key == "first_layer_extrusion_width") {
|
|
||||||
steps.insert(posSupportMaterial);
|
|
||||||
} else if (*opt_key == "interface_shells"
|
|
||||||
|| *opt_key == "infill_only_where_needed"
|
|
||||||
|| *opt_key == "infill_every_layers"
|
|
||||||
|| *opt_key == "solid_infill_every_layers"
|
|
||||||
|| *opt_key == "bottom_solid_layers"
|
|
||||||
|| *opt_key == "top_solid_layers"
|
|
||||||
|| *opt_key == "solid_infill_below_area"
|
|
||||||
|| *opt_key == "infill_extruder"
|
|
||||||
|| *opt_key == "solid_infill_extruder"
|
|
||||||
|| *opt_key == "infill_extrusion_width") {
|
|
||||||
steps.insert(posPrepareInfill);
|
|
||||||
} else if (*opt_key == "top_infill_pattern"
|
|
||||||
|| *opt_key == "bottom_infill_pattern"
|
|
||||||
|| *opt_key == "fill_angle"
|
|
||||||
|| *opt_key == "fill_pattern"
|
|
||||||
|| *opt_key == "top_infill_extrusion_width"
|
|
||||||
|| *opt_key == "first_layer_extrusion_width"
|
|
||||||
|| *opt_key == "infill_overlap") {
|
|
||||||
steps.insert(posInfill);
|
|
||||||
} else if (*opt_key == "fill_density"
|
|
||||||
|| *opt_key == "solid_infill_extrusion_width") {
|
|
||||||
steps.insert(posPerimeters);
|
|
||||||
steps.insert(posPrepareInfill);
|
|
||||||
} else if (*opt_key == "external_perimeter_extrusion_width"
|
|
||||||
|| *opt_key == "perimeter_extruder") {
|
|
||||||
steps.insert(posPerimeters);
|
steps.insert(posPerimeters);
|
||||||
steps.insert(posSupportMaterial);
|
steps.insert(posSupportMaterial);
|
||||||
} else if (*opt_key == "bridge_flow_ratio") {
|
} else if (opt_key == "support_material") {
|
||||||
steps.insert(posPerimeters);
|
steps.insert(posPerimeters);
|
||||||
steps.insert(posInfill);
|
steps.insert(posSupportMaterial);
|
||||||
} else if (*opt_key == "seam_position"
|
} else if (opt_key == "support_material_angle"
|
||||||
|| *opt_key == "support_material_speed"
|
|| opt_key == "support_material_extruder"
|
||||||
|| *opt_key == "bridge_speed"
|
|| opt_key == "support_material_extrusion_width"
|
||||||
|| *opt_key == "external_perimeter_speed"
|
|| opt_key == "support_material_interface_layers"
|
||||||
|| *opt_key == "infill_speed"
|
|| opt_key == "support_material_interface_extruder"
|
||||||
|| *opt_key == "perimeter_speed"
|
|| opt_key == "support_material_interface_spacing"
|
||||||
|| *opt_key == "small_perimeter_speed"
|
|| opt_key == "support_material_interface_speed"
|
||||||
|| *opt_key == "solid_infill_speed"
|
|| opt_key == "support_material_buildplate_only"
|
||||||
|| *opt_key == "top_solid_infill_speed") {
|
|| opt_key == "support_material_pattern"
|
||||||
|
|| opt_key == "support_material_spacing"
|
||||||
|
|| opt_key == "support_material_threshold"
|
||||||
|
|| opt_key == "dont_support_bridges") {
|
||||||
|
steps.insert(posSupportMaterial);
|
||||||
|
} else if (opt_key == "interface_shells"
|
||||||
|
|| opt_key == "infill_only_where_needed") {
|
||||||
|
steps.insert(posPrepareInfill);
|
||||||
|
} else if (opt_key == "seam_position"
|
||||||
|
|| opt_key == "support_material_speed") {
|
||||||
// these options only affect G-code export, so nothing to invalidate
|
// these options only affect G-code export, so nothing to invalidate
|
||||||
} else {
|
} else {
|
||||||
// for legacy, if we can't handle this option let's invalidate all steps
|
// for legacy, if we can't handle this option let's invalidate all steps
|
||||||
return this->invalidate_all_steps();
|
all = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!diff.empty())
|
||||||
|
this->config.apply(config, true);
|
||||||
|
|
||||||
bool invalidated = false;
|
bool invalidated = false;
|
||||||
for (std::set<PrintObjectStep>::const_iterator step = steps.begin(); step != steps.end(); ++step) {
|
if (all) {
|
||||||
if (this->invalidate_step(*step)) invalidated = true;
|
invalidated = this->invalidate_all_steps();
|
||||||
|
} else {
|
||||||
|
for (const PrintObjectStep &step : steps)
|
||||||
|
if (this->invalidate_step(step))
|
||||||
|
invalidated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return invalidated;
|
return invalidated;
|
||||||
|
@ -65,4 +65,91 @@ PrintRegion::flow(FlowRole role, double layer_height, bool bridge, bool first_la
|
|||||||
return Flow::new_from_config_width(role, config_width, nozzle_diameter, layer_height, bridge ? (float)this->config.bridge_flow_ratio : 0.0);
|
return Flow::new_from_config_width(role, config_width, nozzle_diameter, layer_height, bridge ? (float)this->config.bridge_flow_ratio : 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PrintRegion::invalidate_state_by_config(const PrintConfigBase &config)
|
||||||
|
{
|
||||||
|
const t_config_option_keys diff = this->config.diff(config);
|
||||||
|
|
||||||
|
std::set<PrintObjectStep> steps;
|
||||||
|
bool all = false;
|
||||||
|
|
||||||
|
for (const t_config_option_key &opt_key : diff) {
|
||||||
|
if (opt_key == "perimeters"
|
||||||
|
|| opt_key == "extra_perimeters"
|
||||||
|
|| opt_key == "gap_fill_speed"
|
||||||
|
|| opt_key == "overhangs"
|
||||||
|
|| opt_key == "first_layer_extrusion_width"
|
||||||
|
|| opt_key == "perimeter_extrusion_width"
|
||||||
|
|| opt_key == "thin_walls"
|
||||||
|
|| opt_key == "external_perimeters_first") {
|
||||||
|
steps.insert(posPerimeters);
|
||||||
|
} else if (opt_key == "first_layer_extrusion_width") {
|
||||||
|
steps.insert(posSupportMaterial);
|
||||||
|
} else if (opt_key == "infill_every_layers"
|
||||||
|
|| opt_key == "solid_infill_every_layers"
|
||||||
|
|| opt_key == "bottom_solid_layers"
|
||||||
|
|| opt_key == "top_solid_layers"
|
||||||
|
|| opt_key == "solid_infill_below_area"
|
||||||
|
|| opt_key == "infill_extruder"
|
||||||
|
|| opt_key == "solid_infill_extruder"
|
||||||
|
|| opt_key == "infill_extrusion_width") {
|
||||||
|
steps.insert(posPrepareInfill);
|
||||||
|
} else if (opt_key == "top_infill_pattern"
|
||||||
|
|| opt_key == "bottom_infill_pattern"
|
||||||
|
|| opt_key == "fill_angle"
|
||||||
|
|| opt_key == "fill_pattern"
|
||||||
|
|| opt_key == "top_infill_extrusion_width"
|
||||||
|
|| opt_key == "first_layer_extrusion_width"
|
||||||
|
|| opt_key == "infill_overlap") {
|
||||||
|
steps.insert(posInfill);
|
||||||
|
} else if (opt_key == "solid_infill_extrusion_width") {
|
||||||
|
steps.insert(posPerimeters);
|
||||||
|
steps.insert(posPrepareInfill);
|
||||||
|
} else if (opt_key == "fill_density") {
|
||||||
|
const float &cur_value = config.opt<ConfigOptionFloat>("fill_density")->value;
|
||||||
|
const float &new_value = this->config.fill_density.value;
|
||||||
|
if ((cur_value == 0) != (new_value == 0))
|
||||||
|
steps.insert(posPerimeters);
|
||||||
|
|
||||||
|
steps.insert(posPrepareInfill);
|
||||||
|
} else if (opt_key == "external_perimeter_extrusion_width"
|
||||||
|
|| opt_key == "perimeter_extruder") {
|
||||||
|
steps.insert(posPerimeters);
|
||||||
|
steps.insert(posSupportMaterial);
|
||||||
|
} else if (opt_key == "bridge_flow_ratio") {
|
||||||
|
steps.insert(posPerimeters);
|
||||||
|
steps.insert(posInfill);
|
||||||
|
} else if (opt_key == "bridge_speed"
|
||||||
|
|| opt_key == "external_perimeter_speed"
|
||||||
|
|| opt_key == "infill_speed"
|
||||||
|
|| opt_key == "perimeter_speed"
|
||||||
|
|| opt_key == "small_perimeter_speed"
|
||||||
|
|| opt_key == "solid_infill_speed"
|
||||||
|
|| opt_key == "top_solid_infill_speed") {
|
||||||
|
// these options only affect G-code export, so nothing to invalidate
|
||||||
|
} else {
|
||||||
|
// for legacy, if we can't handle this option let's invalidate all steps
|
||||||
|
all = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!diff.empty())
|
||||||
|
this->config.apply(config, true);
|
||||||
|
|
||||||
|
bool invalidated = false;
|
||||||
|
if (all) {
|
||||||
|
for (PrintObject* object : this->print()->objects)
|
||||||
|
if (object->invalidate_all_steps())
|
||||||
|
invalidated = true;
|
||||||
|
} else {
|
||||||
|
for (const PrintObjectStep &step : steps)
|
||||||
|
for (PrintObject* object : this->print()->objects)
|
||||||
|
if (object->invalidate_step(step))
|
||||||
|
invalidated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return invalidated;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,6 @@ _constant()
|
|||||||
Ref<SupportLayer> add_support_layer(int id, coordf_t height, coordf_t print_z);
|
Ref<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);
|
||||||
|
|
||||||
bool invalidate_state_by_config_options(std::vector<std::string> opt_keys);
|
|
||||||
bool invalidate_step(PrintObjectStep step);
|
bool invalidate_step(PrintObjectStep step);
|
||||||
bool invalidate_all_steps();
|
bool invalidate_all_steps();
|
||||||
bool step_done(PrintObjectStep step)
|
bool step_done(PrintObjectStep step)
|
||||||
@ -190,7 +189,6 @@ _constant()
|
|||||||
size_t region_count()
|
size_t region_count()
|
||||||
%code%{ RETVAL = THIS->regions.size(); %};
|
%code%{ RETVAL = THIS->regions.size(); %};
|
||||||
|
|
||||||
bool invalidate_state_by_config_options(std::vector<std::string> opt_keys);
|
|
||||||
bool invalidate_step(PrintStep step);
|
bool invalidate_step(PrintStep step);
|
||||||
bool invalidate_all_steps();
|
bool invalidate_all_steps();
|
||||||
bool step_done(PrintStep step)
|
bool step_done(PrintStep step)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user