diff --git a/src/libslic3r/PrintApply.cpp b/src/libslic3r/PrintApply.cpp index f78f6c52d..761b5cf44 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -97,7 +97,7 @@ static inline void layer_height_ranges_copy_configs(t_layer_config_ranges &lr_ds } } -static inline bool transform3d_lower(const Transform3d &lhs, const Transform3d &rhs) +static inline bool transform3d_lower(const Transform3d &lhs, const Transform3d &rhs) { typedef Transform3d::Scalar T; const T *lv = lhs.data(); @@ -111,7 +111,7 @@ static inline bool transform3d_lower(const Transform3d &lhs, const Transform3d & return false; } -static inline bool transform3d_equal(const Transform3d &lhs, const Transform3d &rhs) +static inline bool transform3d_equal(const Transform3d &lhs, const Transform3d &rhs) { typedef Transform3d::Scalar T; const T *lv = lhs.data(); @@ -434,7 +434,7 @@ struct PrintObjectStatus { New }; - PrintObjectStatus(PrintObject *print_object, Status status = Unknown) : + PrintObjectStatus(PrintObject *print_object, Status status = Unknown) : id(print_object->model_object()->id()), print_object(print_object), trafo(print_object->trafo()), @@ -445,7 +445,7 @@ struct PrintObjectStatus { ObjectID id; // Pointer to the old PrintObject PrintObject *print_object; - // Trafo generated with model_object->world_matrix(true) + // Trafo generated with model_object->world_matrix(true) Transform3d trafo; Status status; @@ -464,7 +464,7 @@ public: } struct iterator_range : std::pair - { + { using std::pair::pair; iterator_range(const std::pair in) : std::pair(in) {} @@ -549,7 +549,7 @@ static PrintObjectRegions::BoundingBox transformed_its_bbox2d(const indexed_tria } static void transformed_its_bboxes_in_z_ranges( - const indexed_triangle_set &its, + const indexed_triangle_set &its, const Transform3f &m, const std::vector &z_ranges, std::vector> &bboxes, @@ -732,7 +732,7 @@ bool verify_update_print_object_regions( assert(next_region_id == int(layer_range.volume_regions.size()) || layer_range.volume_regions[next_region_id].model_volume != region.model_volume || layer_range.volume_regions[next_region_id].parent <= parent_region_id); - if (next_region_id < int(layer_range.volume_regions.size()) && + if (next_region_id < int(layer_range.volume_regions.size()) && layer_range.volume_regions[next_region_id].model_volume == region.model_volume && layer_range.volume_regions[next_region_id].parent == parent_region_id) { // A parent region is already overridden. @@ -767,7 +767,7 @@ bool verify_update_print_object_regions( } } - // Verify and / or update PrintRegions produced by color painting. + // Verify and / or update PrintRegions produced by color painting. for (const PrintObjectRegions::LayerRangeRegions &layer_range : print_object_regions.layer_ranges) for (const PrintObjectRegions::PaintedRegion ®ion : layer_range.painted_regions) { const PrintObjectRegions::VolumeRegion &parent_region = layer_range.volume_regions[region.parent]; @@ -819,7 +819,7 @@ void update_volume_bboxes( std::vector &layer_ranges, std::vector &cached_volume_ids, ModelVolumePtrs model_volumes, - const Transform3d &object_trafo, + const Transform3d &object_trafo, const float offset) { // output will be sorted by the order of model_volumes sorted by their ObjectIDs. @@ -968,7 +968,7 @@ static PrintObjectRegions* generate_print_object_regions( if (parent_volume.is_model_part() || parent_volume.is_modifier()) if (PrintObjectRegions::BoundingBox parent_bbox = find_modifier_volume_extents(layer_range, parent_region_id); parent_bbox.intersects(*bbox)) { // Only create new region for a modifier, which actually modifies config of it's parent. - if (PrintRegionConfig config = region_config_from_model_volume(parent_region.region->config(), nullptr, volume, num_extruders); + if (PrintRegionConfig config = region_config_from_model_volume(parent_region.region->config(), nullptr, volume, num_extruders); config != parent_region.region->config()) { added = true; layer_range.volume_regions.push_back({ &volume, parent_region_id, get_create_region(std::move(config)), bbox }); @@ -1021,7 +1021,16 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ new_full_config.option("printer_settings_id", true); // BBS int used_filaments = this->extruders().size(); - new_full_config.normalize_fdm(used_filaments); + //new_full_config.normalize_fdm(used_filaments); + new_full_config.normalize_fdm_1(); + t_config_option_keys changed_keys = new_full_config.normalize_fdm_2(used_filaments); + if (changed_keys.size() > 0) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got changed_keys, size=%1%")%changed_keys.size(); + for (int i = 0; i < changed_keys.size(); i++) + { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", i=%1%, key=%2%")%i %changed_keys[i]; + } + } // Find modified keys of the various configs. Resolve overrides extruder retract values by filament profiles. DynamicPrintConfig filament_overrides; @@ -1075,13 +1084,14 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ m_default_object_config.apply_only(new_full_config, object_diff, true); // Handle changes to regions config defaults m_default_region_config.apply_only(new_full_config, region_diff, true); - m_full_print_config = std::move(new_full_config); + //m_full_print_config = std::move(new_full_config); + m_full_print_config = new_full_config; if (num_extruders != m_config.filament_diameter.size()) { num_extruders = m_config.filament_diameter.size(); num_extruders_changed = true; } } - + ModelObjectStatusDB model_object_status_db; // 1) Synchronize model objects. @@ -1219,7 +1229,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ if (solid_or_modifier_differ || model_origin_translation_differ || layer_height_ranges_differ || ! model_object.layer_height_profile.timestamp_matches(model_object_new.layer_height_profile)) { // The very first step (the slicing step) is invalidated. One may freely remove all associated PrintObjects. - model_object_status.print_object_regions_status = + model_object_status.print_object_regions_status = model_object_status.print_object_regions == nullptr || model_origin_translation_differ || layer_height_ranges_differ ? // Drop print_objects_regions. ModelObjectStatus::PrintObjectRegionsStatus::Invalid : @@ -1279,7 +1289,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ model_object.name = model_object_new.name; model_object.input_file = model_object_new.input_file; // Only refresh ModelInstances if there is any change. - if (model_object.instances.size() != model_object_new.instances.size() || + if (model_object.instances.size() != model_object_new.instances.size() || ! std::equal(model_object.instances.begin(), model_object.instances.end(), model_object_new.instances.begin(), [](auto l, auto r){ return l->id() == r->id(); })) { // G-code generator accesses model_object.instances to generate sequential print ordering matching the Plater object list. update_apply_status(this->invalidate_step(psGCodeExport)); @@ -1289,8 +1299,8 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ model_object.instances.emplace_back(new ModelInstance(*model_instance)); model_object.instances.back()->set_model_object(&model_object); } - } else if (! std::equal(model_object.instances.begin(), model_object.instances.end(), model_object_new.instances.begin(), - [](auto l, auto r){ return l->print_volume_state == r->print_volume_state && l->printable == r->printable && + } else if (! std::equal(model_object.instances.begin(), model_object.instances.end(), model_object_new.instances.begin(), + [](auto l, auto r){ return l->print_volume_state == r->print_volume_state && l->printable == r->printable && l->get_transformation().get_matrix().isApprox(r->get_transformation().get_matrix()); })) { // If some of the instances changed, the bounding box of the updated ModelObject is likely no more valid. // This is safe as the ModelObject's bounding box is only accessed from this function, which is called from the main thread only. @@ -1397,6 +1407,44 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ } } + //BBS: check the config again + int new_used_filaments = this->extruders().size(); + t_config_option_keys new_changed_keys = new_full_config.normalize_fdm_2(new_used_filaments); + if (new_changed_keys.size() > 0) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got new_changed_keys, size=%1%")%new_changed_keys.size(); + for (int i = 0; i < new_changed_keys.size(); i++) + { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", i=%1%, key=%2%")%i %new_changed_keys[i]; + } + + update_apply_status(false); + + // The following call may stop the background processing. + update_apply_status(this->invalidate_state_by_config_options(new_full_config, new_changed_keys)); + + update_apply_status(this->invalidate_step(psGCodeExport)); + + if (full_config_diff.empty()) { + //BBS: previous empty + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: full_config_diff previous empty, need to apply now.")%__LINE__; + + m_placeholder_parser.clear_config(); + // Set the profile aliases for the PrintBase::output_filename() + m_placeholder_parser.set("print_preset", new_full_config.option("print_settings_id")->clone()); + m_placeholder_parser.set("filament_preset", new_full_config.option("filament_settings_id")->clone()); + m_placeholder_parser.set("printer_preset", new_full_config.option("printer_settings_id")->clone()); + + //m_placeholder_parser.apply_config(filament_overrides); + } + // It is also safe to change m_config now after this->invalidate_state_by_config_options() call. + m_config.apply_only(new_full_config, new_changed_keys, true); + // Handle changes to object config defaults + m_default_object_config.apply_only(new_full_config, new_changed_keys, true); + // Handle changes to regions config defaults + m_default_region_config.apply_only(new_full_config, new_changed_keys, true); + m_full_print_config = std::move(new_full_config); + } + // All regions now have distinct settings. // Check whether applying the new region config defaults we would get different regions, // update regions or create regions from scratch. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index b6874bc1b..6e68ec160 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3834,6 +3834,102 @@ void DynamicPrintConfig::normalize_fdm(int used_filaments) } } +//BBS:divide normalize_fdm to 2 steps and call them one by one in Print::Apply +void DynamicPrintConfig::normalize_fdm_1() +{ + if (this->has("extruder")) { + int extruder = this->option("extruder")->getInt(); + this->erase("extruder"); + if (extruder != 0) { + if (!this->has("sparse_infill_filament")) + this->option("sparse_infill_filament", true)->setInt(extruder); + if (!this->has("wall_filament")) + this->option("wall_filament", true)->setInt(extruder); + // Don't propagate the current extruder to support. + // For non-soluble supports, the default "0" extruder means to use the active extruder, + // for soluble supports one certainly does not want to set the extruder to non-soluble. + // if (!this->has("support_filament")) + // this->option("support_filament", true)->setInt(extruder); + // if (!this->has("support_interface_filament")) + // this->option("support_interface_filament", true)->setInt(extruder); + } + } + + if (!this->has("solid_infill_filament") && this->has("sparse_infill_filament")) + this->option("solid_infill_filament", true)->setInt(this->option("sparse_infill_filament")->getInt()); + + if (this->has("spiral_mode") && this->opt("spiral_mode", true)->value) { + { + // this should be actually done only on the spiral layers instead of all + auto* opt = this->opt("retract_when_changing_layer", true); + opt->values.assign(opt->values.size(), false); // set all values to false + // Disable retract on layer change also for filament overrides. + auto* opt_n = this->opt("filament_retract_when_changing_layer", true); + opt_n->values.assign(opt_n->values.size(), false); // Set all values to false. + } + { + this->opt("wall_loops", true)->value = 1; + this->opt("top_shell_layers", true)->value = 0; + this->opt("sparse_infill_density", true)->value = 0; + } + } + + if (auto *opt_gcode_resolution = this->opt("resolution", false); opt_gcode_resolution) + // Resolution will be above 1um. + opt_gcode_resolution->value = std::max(opt_gcode_resolution->value, 0.001); + + return; +} + +t_config_option_keys DynamicPrintConfig::normalize_fdm_2(int used_filaments) +{ + t_config_option_keys changed_keys; + ConfigOptionBool* ept_opt = this->option("enable_prime_tower"); + if (used_filaments > 0 && ept_opt != nullptr) { + ConfigOptionBool* islh_opt = this->option("independent_support_layer_height", true); + ConfigOptionBool* alh_opt = this->option("adaptive_layer_height"); + ConfigOptionEnum* ps_opt = this->option>("print_sequence"); + + ConfigOptionEnum* timelapse_opt = this->option>("timelapse_type"); + bool is_smooth_timelapse = timelapse_opt != nullptr && timelapse_opt->value == TimelapseType::tlSmooth; + if (!is_smooth_timelapse && (used_filaments == 1 || ps_opt->value == PrintSequence::ByObject)) { + if (ept_opt->value) { + ept_opt->value = false; + changed_keys.push_back("enable_prime_tower"); + } + //ept_opt->value = false; + } + + if (ept_opt->value) { + if (islh_opt) { + if (islh_opt->value) { + islh_opt->value = false; + changed_keys.push_back("independent_support_layer_height"); + } + //islh_opt->value = false; + } + if (alh_opt) { + if (alh_opt->value) { + alh_opt->value = false; + changed_keys.push_back("adaptive_layer_height"); + } + //alh_opt->value = false; + } + } + else { + if (islh_opt) { + if (!islh_opt->value) { + islh_opt->value = true; + changed_keys.push_back("independent_support_layer_height"); + } + //islh_opt->value = true; + } + } + } + + return changed_keys; +} + void handle_legacy_sla(DynamicPrintConfig &config) { for (std::string corr : {"relative_correction", "material_correction"}) { diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 841acb088..16454a447 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -56,7 +56,7 @@ enum InfillPattern : int { ipConcentric, ipRectilinear, ipGrid, ipLine, ipCubic, ipTriangles, ipStars, ipGyroid, ipHoneycomb, ipAdaptiveCubic, ipMonotonic, ipMonotonicLine, ipAlignedRectilinear, ip3DHoneycomb, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipSupportCubic, ipSupportBase, ipConcentricInternal, #if HAS_LIGHTNING_INFILL - ipLightning, + ipLightning, #endif // HAS_LIGHTNING_INFILL ipCount, }; @@ -340,6 +340,9 @@ public: const ConfigDef* def() const override { return &print_config_def; } void normalize_fdm(int used_filaments = 0); + void normalize_fdm_1(); + //return the changed param set + t_config_option_keys normalize_fdm_2(int used_filaments = 0); void set_num_extruders(unsigned int num_extruders); @@ -801,7 +804,7 @@ PRINT_CONFIG_CLASS_DEFINE( // This object is mapped to Perl as Slic3r::Config::Print. PRINT_CONFIG_CLASS_DERIVED_DEFINE( - PrintConfig, + PrintConfig, (MachineEnvelopeConfig, GCodeConfig), //BBS