DynamicPrintConfig::normalize() renamed to normalize_fdm(),

optimization of Print::apply()
This commit is contained in:
Vojtech Bubnik 2020-09-24 19:03:09 +02:00
parent 8f04a76337
commit 7a799be426
7 changed files with 58 additions and 38 deletions

View File

@ -93,7 +93,7 @@ int CLI::run(int argc, char **argv)
return 1; return 1;
m_extra_config.apply(m_config, true); m_extra_config.apply(m_config, true);
m_extra_config.normalize(); m_extra_config.normalize_fdm();
PrinterTechnology printer_technology = Slic3r::printer_technology(m_config); PrinterTechnology printer_technology = Slic3r::printer_technology(m_config);
@ -129,7 +129,7 @@ int CLI::run(int argc, char **argv)
boost::nowide::cerr << "Error while reading config file: " << ex.what() << std::endl; boost::nowide::cerr << "Error while reading config file: " << ex.what() << std::endl;
return 1; return 1;
} }
config.normalize(); config.normalize_fdm();
PrinterTechnology other_printer_technology = Slic3r::printer_technology(config); PrinterTechnology other_printer_technology = Slic3r::printer_technology(config);
if (printer_technology == ptUnknown) { if (printer_technology == ptUnknown) {
printer_technology = other_printer_technology; printer_technology = other_printer_technology;
@ -196,7 +196,7 @@ int CLI::run(int argc, char **argv)
// (command line options override --load files) // (command line options override --load files)
m_print_config.apply(m_extra_config, true); m_print_config.apply(m_extra_config, true);
// Normalizing after importing the 3MFs / AMFs // Normalizing after importing the 3MFs / AMFs
m_print_config.normalize(); m_print_config.normalize_fdm();
// Initialize full print configs for both the FFF and SLA technologies. // Initialize full print configs for both the FFF and SLA technologies.
FullPrintConfig fff_print_config; FullPrintConfig fff_print_config;

View File

@ -587,7 +587,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
new_full_config.option("print_settings_id", true); new_full_config.option("print_settings_id", true);
new_full_config.option("filament_settings_id", true); new_full_config.option("filament_settings_id", true);
new_full_config.option("printer_settings_id", true); new_full_config.option("printer_settings_id", true);
new_full_config.normalize(); new_full_config.normalize_fdm();
// Find modified keys of the various configs. Resolve overrides extruder retract values by filament profiles. // Find modified keys of the various configs. Resolve overrides extruder retract values by filament profiles.
t_config_option_keys print_diff, object_diff, region_diff, full_config_diff; t_config_option_keys print_diff, object_diff, region_diff, full_config_diff;
@ -844,8 +844,8 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
// Only volume IDs, volume types, transformation matrices and their order are checked, configuration and other parameters are NOT checked. // Only volume IDs, volume types, transformation matrices and their order are checked, configuration and other parameters are NOT checked.
bool model_parts_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::MODEL_PART); bool model_parts_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::MODEL_PART);
bool modifiers_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::PARAMETER_MODIFIER); bool modifiers_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::PARAMETER_MODIFIER);
bool support_blockers_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::SUPPORT_BLOCKER); bool supports_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::SUPPORT_BLOCKER) ||
bool support_enforcers_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::SUPPORT_ENFORCER); model_volume_list_changed(model_object, model_object_new, ModelVolumeType::SUPPORT_ENFORCER);
if (model_parts_differ || modifiers_differ || if (model_parts_differ || modifiers_differ ||
model_object.origin_translation != model_object_new.origin_translation || model_object.origin_translation != model_object_new.origin_translation ||
! model_object.layer_height_profile.timestamp_matches(model_object_new.layer_height_profile) || ! model_object.layer_height_profile.timestamp_matches(model_object_new.layer_height_profile) ||
@ -858,20 +858,21 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
} }
// Copy content of the ModelObject including its ID, do not change the parent. // Copy content of the ModelObject including its ID, do not change the parent.
model_object.assign_copy(model_object_new); model_object.assign_copy(model_object_new);
} else if (support_blockers_differ || support_enforcers_differ || model_custom_supports_data_changed(model_object, model_object_new)) { } else if (supports_differ || model_custom_supports_data_changed(model_object, model_object_new)) {
// First stop background processing before shuffling or deleting the ModelVolumes in the ModelObject's list. // First stop background processing before shuffling or deleting the ModelVolumes in the ModelObject's list.
if (supports_differ) {
this->call_cancel_callback(); this->call_cancel_callback();
update_apply_status(false); update_apply_status(false);
}
// Invalidate just the supports step. // Invalidate just the supports step.
auto range = print_object_status.equal_range(PrintObjectStatus(model_object.id())); auto range = print_object_status.equal_range(PrintObjectStatus(model_object.id()));
for (auto it = range.first; it != range.second; ++ it) for (auto it = range.first; it != range.second; ++ it)
update_apply_status(it->print_object->invalidate_step(posSupportMaterial)); update_apply_status(it->print_object->invalidate_step(posSupportMaterial));
if (support_enforcers_differ || support_blockers_differ) { if (supports_differ) {
// Copy just the support volumes. // Copy just the support volumes.
model_volume_list_update_supports(model_object, model_object_new); model_volume_list_update_supports(model_object, model_object_new);
} }
} } else if (model_custom_seam_data_changed(model_object, model_object_new)) {
if (model_custom_seam_data_changed(model_object, model_object_new)) {
update_apply_status(this->invalidate_step(psGCodeExport)); update_apply_status(this->invalidate_step(psGCodeExport));
} }
if (! model_parts_differ && ! modifiers_differ) { if (! model_parts_differ && ! modifiers_differ) {
@ -942,13 +943,20 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
old.emplace_back(&(*it)); old.emplace_back(&(*it));
} }
// Generate a list of trafos and XY offsets for instances of a ModelObject // Generate a list of trafos and XY offsets for instances of a ModelObject
PrintObjectConfig config = PrintObject::object_config_from_model_object(m_default_object_config, *model_object, num_extruders); // Producing the config for PrintObject on demand, caching it at print_object_last.
const PrintObject *print_object_last = nullptr;
auto print_object_apply_config = [this, &print_object_last, model_object, num_extruders](PrintObject* print_object) {
print_object->config_apply(print_object_last ?
print_object_last->config() :
PrintObject::object_config_from_model_object(m_default_object_config, *model_object, num_extruders));
print_object_last = print_object;
};
std::vector<PrintObjectTrafoAndInstances> new_print_instances = print_objects_from_model_object(*model_object); std::vector<PrintObjectTrafoAndInstances> new_print_instances = print_objects_from_model_object(*model_object);
if (old.empty()) { if (old.empty()) {
// Simple case, just generate new instances. // Simple case, just generate new instances.
for (PrintObjectTrafoAndInstances &print_instances : new_print_instances) { for (PrintObjectTrafoAndInstances &print_instances : new_print_instances) {
PrintObject *print_object = new PrintObject(this, model_object, print_instances.trafo, std::move(print_instances.instances)); PrintObject *print_object = new PrintObject(this, model_object, print_instances.trafo, std::move(print_instances.instances));
print_object->config_apply(config); print_object_apply_config(print_object);
print_objects_new.emplace_back(print_object); print_objects_new.emplace_back(print_object);
// print_object_status.emplace(PrintObjectStatus(print_object, PrintObjectStatus::New)); // print_object_status.emplace(PrintObjectStatus(print_object, PrintObjectStatus::New));
new_objects = true; new_objects = true;
@ -965,7 +973,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
if (it_old == old.end() || ! transform3d_equal((*it_old)->trafo, new_instances.trafo)) { if (it_old == old.end() || ! transform3d_equal((*it_old)->trafo, new_instances.trafo)) {
// This is a new instance (or a set of instances with the same trafo). Just add it. // This is a new instance (or a set of instances with the same trafo). Just add it.
PrintObject *print_object = new PrintObject(this, model_object, new_instances.trafo, std::move(new_instances.instances)); PrintObject *print_object = new PrintObject(this, model_object, new_instances.trafo, std::move(new_instances.instances));
print_object->config_apply(config); print_object_apply_config(print_object);
print_objects_new.emplace_back(print_object); print_objects_new.emplace_back(print_object);
// print_object_status.emplace(PrintObjectStatus(print_object, PrintObjectStatus::New)); // print_object_status.emplace(PrintObjectStatus(print_object, PrintObjectStatus::New));
new_objects = true; new_objects = true;

View File

@ -3233,7 +3233,7 @@ PrinterTechnology printer_technology(const ConfigBase &cfg)
return ptUnknown; return ptUnknown;
} }
void DynamicPrintConfig::normalize() void DynamicPrintConfig::normalize_fdm()
{ {
if (this->has("extruder")) { if (this->has("extruder")) {
int extruder = this->option("extruder")->getInt(); int extruder = this->option("extruder")->getInt();

View File

@ -254,7 +254,7 @@ public:
// Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here. // Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here.
const ConfigDef* def() const override { return &print_config_def; } const ConfigDef* def() const override { return &print_config_def; }
void normalize(); void normalize_fdm();
void set_num_extruders(unsigned int num_extruders); void set_num_extruders(unsigned int num_extruders);
@ -269,14 +269,6 @@ public:
{ PrintConfigDef::handle_legacy(opt_key, value); } { PrintConfigDef::handle_legacy(opt_key, value); }
}; };
template<typename CONFIG>
void normalize_and_apply_config(CONFIG &dst, const DynamicPrintConfig &src)
{
DynamicPrintConfig src_normalized(src);
src_normalized.normalize();
dst.apply(src_normalized, true);
}
class StaticPrintConfig : public StaticConfig class StaticPrintConfig : public StaticConfig
{ {
public: public:
@ -1457,8 +1449,6 @@ private:
static uint64_t s_last_timestamp; static uint64_t s_last_timestamp;
}; };
template<typename CONFIG> void normalize_and_apply_config(CONFIG& dst, const ModelConfig& src) { normalize_and_apply_config(dst, src.get()); }
} // namespace Slic3r } // namespace Slic3r
// Serialization through the Cereal library // Serialization through the Cereal library

View File

@ -1544,22 +1544,46 @@ static void clamp_exturder_to_default(ConfigOptionInt &opt, size_t num_extruders
PrintObjectConfig PrintObject::object_config_from_model_object(const PrintObjectConfig &default_object_config, const ModelObject &object, size_t num_extruders) PrintObjectConfig PrintObject::object_config_from_model_object(const PrintObjectConfig &default_object_config, const ModelObject &object, size_t num_extruders)
{ {
PrintObjectConfig config = default_object_config; PrintObjectConfig config = default_object_config;
normalize_and_apply_config(config, object.config); {
DynamicPrintConfig src_normalized(object.config.get());
src_normalized.normalize_fdm();
config.apply(src_normalized, true);
}
// Clamp invalid extruders to the default extruder (with index 1). // Clamp invalid extruders to the default extruder (with index 1).
clamp_exturder_to_default(config.support_material_extruder, num_extruders); clamp_exturder_to_default(config.support_material_extruder, num_extruders);
clamp_exturder_to_default(config.support_material_interface_extruder, num_extruders); clamp_exturder_to_default(config.support_material_interface_extruder, num_extruders);
return config; return config;
} }
static void apply_to_print_region_config(PrintRegionConfig &out, const DynamicPrintConfig &in)
{
// 1) Copy the "extruder key to infill_extruder and perimeter_extruder.
std::string sextruder = "extruder";
auto *opt_extruder = in.opt<ConfigOptionInt>(sextruder);
if (opt_extruder) {
if (opt_extruder->value != 0) {
out.infill_extruder.value = opt_extruder->value;
out.perimeter_extruder.value = opt_extruder->value;
}
}
// 2) Copy the rest of the values.
for (auto it = in.cbegin(); it != in.cend(); ++ it)
if (it->first != sextruder) {
ConfigOption *my_opt = out.option(it->first, false);
if (my_opt)
my_opt->set(it->second.get());
}
}
PrintRegionConfig PrintObject::region_config_from_model_volume(const PrintRegionConfig &default_region_config, const DynamicPrintConfig *layer_range_config, const ModelVolume &volume, size_t num_extruders) PrintRegionConfig PrintObject::region_config_from_model_volume(const PrintRegionConfig &default_region_config, const DynamicPrintConfig *layer_range_config, const ModelVolume &volume, size_t num_extruders)
{ {
PrintRegionConfig config = default_region_config; PrintRegionConfig config = default_region_config;
normalize_and_apply_config(config, volume.get_object()->config); apply_to_print_region_config(config, volume.get_object()->config.get());
if (layer_range_config != nullptr) if (layer_range_config != nullptr)
normalize_and_apply_config(config, *layer_range_config); apply_to_print_region_config(config, *layer_range_config);
normalize_and_apply_config(config, volume.config); apply_to_print_region_config(config, volume.config.get());
if (! volume.material_id().empty()) if (! volume.material_id().empty())
normalize_and_apply_config(config, volume.material()->config); apply_to_print_region_config(config, volume.material()->config.get());
// Clamp invalid extruders to the default extruder (with index 1). // Clamp invalid extruders to the default extruder (with index 1).
clamp_exturder_to_default(config.infill_extruder, num_extruders); clamp_exturder_to_default(config.infill_extruder, num_extruders);
clamp_exturder_to_default(config.perimeter_extruder, num_extruders); clamp_exturder_to_default(config.perimeter_extruder, num_extruders);

View File

@ -185,7 +185,6 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
config.option("sla_print_settings_id", true); config.option("sla_print_settings_id", true);
config.option("sla_material_settings_id", true); config.option("sla_material_settings_id", true);
config.option("printer_settings_id", true); config.option("printer_settings_id", true);
config.normalize();
// Collect changes to print config. // Collect changes to print config.
t_config_option_keys print_diff = m_print_config.diff(config); t_config_option_keys print_diff = m_print_config.diff(config);
t_config_option_keys printer_diff = m_printer_config.diff(config); t_config_option_keys printer_diff = m_printer_config.diff(config);
@ -400,7 +399,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
model_object.config.assign_config(model_object_new.config); model_object.config.assign_config(model_object_new.config);
if (! object_diff.empty() || object_config_changed) { if (! object_diff.empty() || object_config_changed) {
SLAPrintObjectConfig new_config = m_default_object_config; SLAPrintObjectConfig new_config = m_default_object_config;
normalize_and_apply_config(new_config, model_object.config); new_config.apply(model_object.config.get(), true);
if (it_print_object_status != print_object_status.end()) { if (it_print_object_status != print_object_status.end()) {
t_config_option_keys diff = it_print_object_status->print_object->config().diff(new_config); t_config_option_keys diff = it_print_object_status->print_object->config().diff(new_config);
if (! diff.empty()) { if (! diff.empty()) {
@ -464,9 +463,8 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
print_object->set_instances(std::move(new_instances)); print_object->set_instances(std::move(new_instances));
SLAPrintObjectConfig new_config = m_default_object_config; print_object->config_apply(m_default_object_config, true);
normalize_and_apply_config(new_config, model_object.config); print_object->config_apply(model_object.config.get(), true);
print_object->config_apply(new_config, true);
print_objects_new.emplace_back(print_object); print_objects_new.emplace_back(print_object);
new_objects = true; new_objects = true;
} }

View File

@ -261,7 +261,7 @@ protected:
SLAPrintObject(SLAPrint* print, ModelObject* model_object); SLAPrintObject(SLAPrint* print, ModelObject* model_object);
~SLAPrintObject(); ~SLAPrintObject();
void config_apply(const ConfigBase &other, bool ignore_nonexistent = false) { this->m_config.apply(other, ignore_nonexistent); } void config_apply(const ConfigBase &other, bool ignore_nonexistent = false) { m_config.apply(other, ignore_nonexistent); }
void config_apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false) void config_apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false)
{ this->m_config.apply_only(other, keys, ignore_nonexistent); } { this->m_config.apply_only(other, keys, ignore_nonexistent); }