From 766abf92fa3b1e1f0fd31581babe5c819226c3fc Mon Sep 17 00:00:00 2001 From: "salt.wei" Date: Wed, 21 Jun 2023 15:51:01 +0800 Subject: [PATCH] ENH: add back use_relative_e for third party printer Useless for BambuPrinter. But used by third party printer Signed-off-by: salt.wei Change-Id: Ib6a63e78816b25696c25952508f76c3d9221e363 --- src/libslic3r/Extruder.cpp | 8 ++++---- src/libslic3r/Extruder.hpp | 4 ++-- src/libslic3r/GCode.cpp | 8 ++++---- src/libslic3r/GCode/CoolingBuffer.cpp | 2 +- src/libslic3r/GCode/SpiralVase.cpp | 2 +- src/libslic3r/GCodeReader.cpp | 2 +- src/libslic3r/GCodeWriter.cpp | 8 +++----- src/libslic3r/Preset.cpp | 3 ++- src/libslic3r/Print.cpp | 3 +++ src/libslic3r/PrintConfig.cpp | 7 +++++++ src/libslic3r/PrintConfig.hpp | 1 + src/libslic3r/libslic3r.h | 4 ---- src/slic3r/GUI/Tab.cpp | 2 ++ 13 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/libslic3r/Extruder.cpp b/src/libslic3r/Extruder.cpp index 61b80d349f..9ba2b4c869 100644 --- a/src/libslic3r/Extruder.cpp +++ b/src/libslic3r/Extruder.cpp @@ -22,7 +22,7 @@ double Extruder::extrude(double dE) { // BBS if (m_share_extruder) { - if (RELATIVE_E_AXIS) + if (m_config->use_relative_e_distances) m_share_E = 0.; m_share_E += dE; m_absolute_E += dE; @@ -30,7 +30,7 @@ double Extruder::extrude(double dE) m_share_retracted -= dE; } else { // in case of relative E distances we always reset to 0 before any output - if (RELATIVE_E_AXIS) + if (m_config->use_relative_e_distances) m_E = 0.; m_E += dE; m_absolute_E += dE; @@ -51,7 +51,7 @@ double Extruder::retract(double length, double restart_extra) { // BBS if (m_share_extruder) { - if (RELATIVE_E_AXIS) + if (m_config->use_relative_e_distances) m_share_E = 0.; double to_retract = std::max(0., length - m_share_retracted); if (to_retract > 0.) { @@ -62,7 +62,7 @@ double Extruder::retract(double length, double restart_extra) return to_retract; } else { // in case of relative E distances we always reset to 0 before any output - if (RELATIVE_E_AXIS) + if (m_config->use_relative_e_distances) m_E = 0.; double to_retract = std::max(0., length - m_retracted); if (to_retract > 0.) { diff --git a/src/libslic3r/Extruder.hpp b/src/libslic3r/Extruder.hpp index 278e941cf9..ec9b14c23a 100644 --- a/src/libslic3r/Extruder.hpp +++ b/src/libslic3r/Extruder.hpp @@ -34,7 +34,7 @@ public: double retract(double length, double restart_extra); double unretract(); double E() const { return m_share_extruder ? m_share_E : m_E; } - void reset_E() { m_E = 0.; } + void reset_E() { m_E = 0.; m_share_E = 0.; } double e_per_mm(double mm3_per_mm) const { return mm3_per_mm * m_e_per_mm3; } double e_per_mm3() const { return m_e_per_mm3; } // Used filament volume in mm^3. @@ -64,7 +64,7 @@ private: GCodeConfig *m_config; // Print-wide global ID of this extruder. unsigned int m_id; - // Current state of the extruder axis, may be resetted if relative_e_axis. + // Current state of the extruder axis, may be resetted if use_relative_e_distance. double m_E; // Current state of the extruder tachometer, used to output the extruded_volume() and used_filament() statistics. double m_absolute_E; diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index c54cdee1fa..ec732c9011 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -478,7 +478,7 @@ static std::vector get_path_of_change_filament(const Print& print) new_filament_e_feedrate = new_filament_e_feedrate == 0 ? 100 : new_filament_e_feedrate; config.set_key_value("max_layer_z", new ConfigOptionFloat(gcodegen.m_max_layer_z)); - config.set_key_value("relative_e_axis", new ConfigOptionBool(RELATIVE_E_AXIS)); + config.set_key_value("relative_e_axis", new ConfigOptionBool(full_config.use_relative_e_distances)); config.set_key_value("toolchange_count", new ConfigOptionInt((int)gcodegen.m_toolchange_count)); //BBS: fan speed is useless placeholer now, but we don't remove it to avoid //slicing error in old change_filament_gcode in old 3MF @@ -3198,7 +3198,7 @@ GCode::LayerResult GCode::process_layer( get_instance_name(&instance_to_print.print_object, inst.id) + "\n"; reset_e = true; } - if (reset_e && !RELATIVE_E_AXIS) + if (reset_e && !m_config.use_relative_e_distances) gcode += m_writer.reset_e(true); // When starting a new object, use the external motion planner for the first travel move. @@ -3301,7 +3301,7 @@ GCode::LayerResult GCode::process_layer( get_instance_name(&instance_to_print.print_object, inst.id) + "\n"; reset_e = true; } - if (reset_e && !RELATIVE_E_AXIS) + if (reset_e && !m_config.use_relative_e_distances) gcode += m_writer.reset_e(true); } } @@ -4483,7 +4483,7 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z) dyn_config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index)); dyn_config.set_key_value("layer_z", new ConfigOptionFloat(print_z)); dyn_config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z)); - dyn_config.set_key_value("relative_e_axis", new ConfigOptionBool(RELATIVE_E_AXIS)); + dyn_config.set_key_value("relative_e_axis", new ConfigOptionBool(m_config.use_relative_e_distances)); dyn_config.set_key_value("toolchange_count", new ConfigOptionInt((int)m_toolchange_count)); //BBS: fan speed is useless placeholer now, but we don't remove it to avoid //slicing error in old change_filament_gcode in old 3MF diff --git a/src/libslic3r/GCode/CoolingBuffer.cpp b/src/libslic3r/GCode/CoolingBuffer.cpp index 863cf09630..54e060c958 100644 --- a/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/src/libslic3r/GCode/CoolingBuffer.cpp @@ -401,7 +401,7 @@ std::vector CoolingBuffer::parse_layer_gcode(const std:: } if ((line.type & CoolingLine::TYPE_G92) == 0) { //BBS: G0, G1, G2, G3. Calculate the duration. - if (RELATIVE_E_AXIS) + if (m_config.use_relative_e_distances.value) // Reset extruder accumulator. current_pos[3] = 0.f; float dif[4]; diff --git a/src/libslic3r/GCode/SpiralVase.cpp b/src/libslic3r/GCode/SpiralVase.cpp index 9fc70042fc..c3caee2dc4 100644 --- a/src/libslic3r/GCode/SpiralVase.cpp +++ b/src/libslic3r/GCode/SpiralVase.cpp @@ -54,7 +54,7 @@ std::string SpiralVase::process_layer(const std::string &gcode) // For absolute extruder distances it will be switched off. // Tapering the absolute extruder distances requires to process every extrusion value after the first transition // layer. - bool transition = m_transition_layer && RELATIVE_E_AXIS; + bool transition = m_transition_layer && m_config.use_relative_e_distances.value; float layer_height_factor = layer_height / total_layer_length; float len = 0.f; m_reader.parse_buffer(gcode, [&new_gcode, &z, total_layer_length, layer_height_factor, transition, &len] diff --git a/src/libslic3r/GCodeReader.cpp b/src/libslic3r/GCodeReader.cpp index e1314003a4..1a660b4c12 100644 --- a/src/libslic3r/GCodeReader.cpp +++ b/src/libslic3r/GCodeReader.cpp @@ -82,7 +82,7 @@ const char* GCodeReader::parse_line_internal(const char *ptr, const char *end, G } } - if (gline.has(E) && RELATIVE_E_AXIS) + if (gline.has(E) && m_config.use_relative_e_distances) m_position[E] = 0; // Skip the rest of the line. diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index c659d7216d..8a9f3488b8 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -60,11 +60,9 @@ std::string GCodeWriter::preamble() FLAVOR_IS(gcfSmoothie) || FLAVOR_IS(gcfKlipper)) { - if (RELATIVE_E_AXIS) { - gcode << "M83 ; only support relative e\n"; + if (this->config.use_relative_e_distances) { + gcode << "M83 ; use relative distances for extrusion\n"; } else { - //BBS: don't support absolute e distance - assert(0); gcode << "M82 ; use absolute distances for extrusion\n"; } gcode << this->reset_e(true); @@ -243,7 +241,7 @@ std::string GCodeWriter::reset_e(bool force) m_extruder->reset_E(); } - if (! RELATIVE_E_AXIS) { + if (!this->config.use_relative_e_distances) { std::ostringstream gcode; gcode << "G92 E0"; //BBS diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 7409d7705a..fe85d55135 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -836,7 +836,8 @@ static std::vector s_Preset_printer_options { "host_type", "print_host", "printhost_apikey", "print_host_webui", "printhost_cafile","printhost_port","printhost_authorization_type", - "printhost_user", "printhost_password", "printhost_ssl_ignore_revoke" + "printhost_user", "printhost_password", "printhost_ssl_ignore_revoke", + "use_relative_e_distances" }; static std::vector s_Preset_sla_print_options { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 6caca2737d..ee6cf880e3 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -162,6 +162,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "inner_wall_acceleration", "sparse_infill_acceleration", "exclude_object", + "use_relative_e_distances" }; static std::unordered_set steps_ignore; @@ -973,6 +974,8 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons* return { ("Different nozzle diameters and different filament diameters is not allowed when prime tower is enabled.") }; } + if (! m_config.use_relative_e_distances) + return { ("The Wipe Tower is currently only supported with the relative extruder addressing (use_relative_e_distances=1).") }; if (m_config.ooze_prevention) return { ("Ooze prevention is currently not supported with the prime tower enabled.") }; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 34585fbdef..151ecda875 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3158,6 +3158,13 @@ void PrintConfigDef::init_fff_params() def->mode = comDevelop; def->set_default_value(new ConfigOptionFloat(0.)); + def = this->add("use_relative_e_distances", coBool); + def->label = L("Use relative E distances"); + def->tooltip = L("If your firmware requires relative E values, check this, " + "otherwise leave it unchecked. Must use relative e distance for Bambu printer"); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionBool(true)); + def = this->add("wipe", coBools); def->label = L("Wipe while retracting"); def->tooltip = L("Move nozzle along the last extrusion path when retracting to clean leaked material on nozzle. " diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 475e6a5aa7..696ca569e4 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -854,6 +854,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionString, change_filament_gcode)) ((ConfigOptionFloat, travel_speed)) ((ConfigOptionFloat, travel_speed_z)) + ((ConfigOptionBool, use_relative_e_distances)) ((ConfigOptionBool, silent_mode)) ((ConfigOptionString, machine_pause_gcode)) ((ConfigOptionString, template_custom_gcode)) diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index c4891473b8..1bbfec8860 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -78,10 +78,6 @@ static constexpr double BRIDGE_INFILL_MARGIN = 1; #define scale_(val) ((val) / SCALING_FACTOR) #define unscale_(val) ((val) * SCALING_FACTOR) -//BBS: BBS only support relative E and can't been changed by user at the moment. because -//BBS need to support skip object when printing. -static constexpr bool RELATIVE_E_AXIS = 1; - #define SCALED_EPSILON scale_(EPSILON) #ifndef UNUSED diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 4920adee62..3a0da5faf5 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3068,6 +3068,7 @@ void TabPrinter::build_fff() optgroup = page->new_optgroup(L("Advanced"), L"param_advanced"); optgroup->append_single_option_line("gcode_flavor"); optgroup->append_single_option_line("scan_first_layer"); + optgroup->append_single_option_line("use_relative_e_distances"); // optgroup->append_single_option_line("spaghetti_detector"); optgroup->append_single_option_line("machine_load_filament_time"); optgroup->append_single_option_line("machine_unload_filament_time"); @@ -3632,6 +3633,7 @@ void TabPrinter::toggle_options() toggle_option("single_extruder_multi_material", have_multiple_extruders); //BBS: gcode_flavore of BBL printer can't be edited and changed toggle_option("gcode_flavor", !is_BBL_printer); + toggle_option("use_relative_e_distances", !is_BBL_printer); auto flavor = m_config->option>("gcode_flavor")->value; bool is_marlin_flavor = flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware;