From 57916c74524898e5c74b80ccca6fc3503c8c29b9 Mon Sep 17 00:00:00 2001 From: "zhimin.zeng" Date: Thu, 13 Jun 2024 14:11:46 +0800 Subject: [PATCH] FIX: Use the same api to get the extruder id jira: none Change-Id: I05b3040b176374deee3e95bc52364fe7b33bb257 (cherry picked from commit 8b2544df41456377b09719de15460b19b7c71e09) --- src/libslic3r/Extruder.cpp | 5 +++++ src/libslic3r/Extruder.hpp | 8 +------- src/libslic3r/GCode.cpp | 8 ++++---- src/libslic3r/GCode.hpp | 5 ----- src/libslic3r/PresetBundle.cpp | 6 ++++++ src/libslic3r/PresetBundle.hpp | 3 ++- src/libslic3r/PrintConfig.cpp | 33 ++++++++++++++++++++------------- src/libslic3r/PrintConfig.hpp | 1 + src/libslic3r/PrintObject.cpp | 1 + 9 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/libslic3r/Extruder.cpp b/src/libslic3r/Extruder.cpp index 3709a38ce7..664b5e9ae1 100644 --- a/src/libslic3r/Extruder.cpp +++ b/src/libslic3r/Extruder.cpp @@ -18,6 +18,11 @@ Extruder::Extruder(unsigned int id, GCodeConfig *config, bool share_extruder) : m_e_per_mm3 /= this->filament_crossection(); } +unsigned int Extruder::extruder_id() const +{ + return get_extruder_index(m_id); +} + double Extruder::extrude(double dE) { // BBS diff --git a/src/libslic3r/Extruder.hpp b/src/libslic3r/Extruder.hpp index 6e0571d421..36c135f999 100644 --- a/src/libslic3r/Extruder.hpp +++ b/src/libslic3r/Extruder.hpp @@ -29,13 +29,7 @@ public: unsigned int id() const { return m_id; } - unsigned int extruder_id() const - { - //TODO: get extruder id - unsigned int extruder_id = -1; - // get matched id - return extruder_id; - } + unsigned int extruder_id() const; double extrude(double dE); double retract(double length, double restart_extra); double unretract(); diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 5ce9cdc11f..fe50535469 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -435,7 +435,7 @@ static std::vector get_path_of_change_filament(const Print& print) if (new_filament_id != -1 && new_filament_id != tcr.new_tool) throw Slic3r::InvalidArgument("Error: WipeTowerIntegration::append_tcr was asked to do a toolchange it didn't expect."); - int new_extruder_id = gcodegen.get_extruder_id(new_filament_id); + int new_extruder_id = get_extruder_index(new_filament_id); std::string gcode; // Toolchangeresult.gcode assumes the wipe tower corner is at the origin (except for priming lines) @@ -2155,13 +2155,13 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato m_cooling_buffer = make_unique(*this); m_cooling_buffer->set_current_extruder(initial_extruder_id); - int extruder_id = get_extruder_id(initial_extruder_id); + int extruder_id = get_extruder_index(initial_extruder_id); // Orca: Initialise AdaptivePA processor filter m_pa_processor = std::make_unique(*this, tool_ordering.all_extruders()); // Emit machine envelope limits for the Marlin firmware. - this->print_machine_envelope(file, print); + this->print_machine_envelope(file, print, initial_extruder_id); // Disable fan. if (m_config.auxiliary_fan.value && print.config().close_fan_the_first_x_layers.get_at(initial_extruder_id)) { @@ -6370,7 +6370,7 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li std::string GCode::set_extruder(unsigned int filament_id, double print_z, bool by_object) { - int extruder_id = get_extruder_id(filament_id); + int extruder_id = get_extruder_index(filament_id); if (!m_writer.need_toolchange(filament_id)) return ""; diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 3d04acc77c..a892cc5dc7 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -193,11 +193,6 @@ public: // throws std::runtime_exception on error, // throws CanceledException through print->throw_if_canceled(). void do_export(Print* print, const char* path, GCodeProcessorResult* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr); - int get_extruder_id(unsigned int) { - //TODO: get matched extruder - int extruder_id = -1; - return extruder_id; - }; //BBS: set offset for gcode writer void set_gcode_offset(double x, double y) { m_writer.set_xy_offset(x, y); m_processor.set_xy_offset(x, y);} diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 141879176e..e5d6148838 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -2119,6 +2119,12 @@ DynamicPrintConfig PresetBundle::full_fff_config() const // BBS size_t num_filaments = this->filament_presets.size(); + + // todo multi_extruders: to delete + for (size_t i = 0; i < num_filaments; ++i) { + this->filament_maps.push_back(1); + } + auto* extruder_diameter = dynamic_cast(out.option("nozzle_diameter")); // Collect the "compatible_printers_condition" and "inherits" values over all presets (print, filaments, printers) into a single vector. std::vector compatible_printers_condition; diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 5d67fd1aa8..53674002b3 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -150,7 +150,8 @@ public: std::map filament_ams_list; std::vector> ams_multi_color_filment; - std::vector filament_maps; + // todo multi_extruders: delete mutable + mutable std::vector filament_maps; // Calibrate Preset const * calibrate_printer = nullptr; std::set calibrate_filaments; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index e3aef8acdb..8a1d8169c7 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -53,6 +53,12 @@ namespace Slic3r { #define L(s) (s) #define _(s) Slic3r::I18N::translate(s) +size_t get_extruder_index(unsigned int filament_id) +{ + // todo multi_extruders: + return 0; +} + static t_config_enum_names enum_names_from_keys_map(const t_config_enum_values &enum_keys_map) { t_config_enum_names names; @@ -7486,13 +7492,14 @@ bool DynamicPrintConfig::support_different_extruders(int& extruder_count) int size = nozzle_diameters_opt->size(); extruder_count = size; auto extruder_variant_opt = dynamic_cast(this->option("extruder_variant_list")); - for (int index = 0; index < size; index++) - { - std::string variant = extruder_variant_opt->get_at(index); - std::vector variants_list; - boost::split(variants_list, variant, boost::is_any_of(","), boost::token_compress_on); - if (!variants_list.empty()) - variant_set.insert(variants_list.begin(), variants_list.end()); + if (extruder_variant_opt != nullptr) { + for (int index = 0; index < size; index++) { + std::string variant = extruder_variant_opt->get_at(index); + std::vector variants_list; + boost::split(variants_list, variant, boost::is_any_of(","), boost::token_compress_on); + if (!variants_list.empty()) + variant_set.insert(variants_list.begin(), variants_list.end()); + } } } @@ -7532,14 +7539,14 @@ void DynamicPrintConfig::update_values_to_printer_extruders(std::vectoroption("nozzle_diameter"); //int extruder_count = opt_nozzle_diameters->size(); - auto opt_extruder_type = dynamic_cast(this->option("extruder_type")); - auto opt_nozzle_volume_type = dynamic_cast(this->option("nozzle_volume_type")); + //auto opt_extruder_type = dynamic_cast(this->option("extruder_type")); + //auto opt_nozzle_volume_type = dynamic_cast(this->option("nozzle_volume_type")); std::vector variant_index; if (extruder_id > 0 && extruder_id < extruder_count) { variant_index.resize(1); - ExtruderType extruder_type = (ExtruderType)(opt_extruder_type->get_at(extruder_id - 1)); - NozzleVolumeType nozzle_volume_type = (NozzleVolumeType)(opt_nozzle_volume_type->get_at(extruder_id - 1)); + ExtruderType extruder_type = ExtruderType::etDirectDrive; // TODO:Orca hack (ExtruderType)(opt_extruder_type->get_at(extruder_id - 1)); + NozzleVolumeType nozzle_volume_type = NozzleVolumeType::nvtNormal; // TODO:Orca hack (NozzleVolumeType)(opt_nozzle_volume_type->get_at(extruder_id - 1)); //variant index variant_index[0] = get_index_for_extruder(extruder_id, id_name, extruder_type, nozzle_volume_type, variant_name); @@ -7551,8 +7558,8 @@ void DynamicPrintConfig::update_values_to_printer_extruders(std::vectorget_at(e_index)); - NozzleVolumeType nozzle_volume_type = (NozzleVolumeType)(opt_nozzle_volume_type->get_at(e_index)); + ExtruderType extruder_type = ExtruderType::etDirectDrive; // TODO:Orca hack (ExtruderType)(opt_extruder_type->get_at(e_index)); + NozzleVolumeType nozzle_volume_type = NozzleVolumeType::nvtNormal; // (NozzleVolumeType)(opt_nozzle_volume_type->get_at(e_index)); //variant index variant_index[e_index] = get_index_for_extruder(e_index+1, id_name, extruder_type, nozzle_volume_type, variant_name); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 1c88ba373e..6c1ae294c0 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -457,6 +457,7 @@ static std::string get_bed_temp_1st_layer_key(const BedType type) return ""; } +size_t get_extruder_index(unsigned int filament_id); #define CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(NAME) \ template<> const t_config_enum_names& ConfigOptionEnum::get_enum_names(); \ template<> const t_config_enum_values& ConfigOptionEnum::get_enum_values(); diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index bf56528e98..4878ff6049 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -927,6 +927,7 @@ bool PrintObject::invalidate_state_by_config_options( } else if (opt_key == "gap_infill_speed" || opt_key == "filter_out_gap_fill" ) { // Return true if gap-fill speed has changed from zero value to non-zero or from non-zero value to zero. + // todo multi_extruders: Parameter migration between single and double extruder printers auto is_gap_fill_changed_state_due_to_speed = [&opt_key, &old_config, &new_config]() -> bool { if (opt_key == "gap_infill_speed") { const auto *old_gap_fill_speed = old_config.option(opt_key);