From 5692e02c54745f728c772d992708f3be99302506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrice=20C=C3=B4t=C3=A9?= Date: Tue, 24 Jan 2023 00:02:52 -0500 Subject: [PATCH] Enable absolute/relative extrusion option on non BBL printers (#205) Add the option to use non-relative extrusion in printer config screen. Some extruders do not play well with relative extrusion... Remove reference to multi-extruder Remove reference to multi-extruder change g-code comment for M83 relative extrusion changed comment for M83 Remove commented line of code In this specific case, we delete the old line of code because it refers to a variable that was deleted from the rest of the code (RELATIVE_E_AXIS) --- src/libslic3r/Extruder.cpp | 8 ++++---- src/libslic3r/Extruder.hpp | 4 ++-- src/libslic3r/GCode.cpp | 14 +++++++++----- 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 | 2 +- src/libslic3r/Print.cpp | 9 ++++++--- src/libslic3r/PrintConfig.cpp | 11 ++++++++++- src/libslic3r/PrintConfig.hpp | 4 ++-- src/libslic3r/libslic3r.h | 4 ---- src/slic3r/GUI/Tab.cpp | 3 +++ 13 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/libslic3r/Extruder.cpp b/src/libslic3r/Extruder.cpp index a4e6ea0c14..4621600f2e 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.) { @@ -63,7 +63,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 d7b97be911..9769d70c95 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. @@ -66,7 +66,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_distances. 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 bee4593b60..9e0eb1b81a 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -355,7 +355,6 @@ bool GCode::gcode_label_objects = true; 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("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 @@ -1632,7 +1631,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato std::function throw_if_canceled_func = [&print]() { print.throw_if_canceled(); }; m_seam_placer.init(print, throw_if_canceled_func); - // BBS: priming logic is removed, always set first extruer here. + // BBS: priming logic is removed, always set first extruder here. //if (! (has_wipe_tower && print.config().single_extruder_multi_material_priming)) { // Set initial extruder only after custom start G-code. @@ -3066,8 +3065,11 @@ GCode::LayerResult GCode::process_layer( m_object_layer_over_raft = object_layer_over_raft; if (m_config.reduce_crossing_wall) m_avoid_crossing_perimeters.init_layer(*m_layer); - if (GCode::gcode_label_objects) + if (GCode::gcode_label_objects) { gcode += std::string("; printing object ") + instance_to_print.print_object.model_object()->name + " id:" + std::to_string(instance_to_print.layer_id) + " copy " + std::to_string(instance_to_print.instance_id) + "\n"; + if (!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. const Point &offset = instance_to_print.print_object.instances()[instance_to_print.instance_id].shift; std::pair this_object_copy(&instance_to_print.print_object, offset); @@ -3158,8 +3160,11 @@ GCode::LayerResult GCode::process_layer( // ironing gcode += this->extrude_infill(print,by_region_specific, true); } - if (GCode::gcode_label_objects) + if (GCode::gcode_label_objects) { gcode += std::string("; stop printing object ") + instance_to_print.print_object.model_object()->name + " id:" + std::to_string(instance_to_print.layer_id) + " copy " + std::to_string(instance_to_print.instance_id) + "\n"; + if (!m_config.use_relative_e_distances) + gcode += m_writer.reset_e(true); + } } } } @@ -4213,7 +4218,6 @@ 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("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 f1b1d97b6d..fc67b6bd8a 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..f83ed22a98 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; 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 2ebfc181fc..5dbf5f5530 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -61,11 +61,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); @@ -246,7 +244,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 4836142941..f16e986c7b 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -803,7 +803,7 @@ static std::vector s_Preset_printer_options { "printhost_cafile","printhost_port","printhost_authorization_type", "printhost_user", "printhost_password", "printhost_ssl_ignore_revoke", "z_lift_type", "thumbnails", - "use_firmware_retraction" + "use_firmware_retraction", "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 3a69831c74..42412618f0 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -152,7 +152,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n // SoftFever "seam_gap", "role_based_wipe_speed", - "wipe_speed" + "wipe_speed", + "use_relative_e_distances" }; static std::unordered_set steps_ignore; @@ -917,7 +918,10 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons* // BBS: remove L() 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.") }; @@ -1120,7 +1124,6 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons* } } - const ConfigOptionDef* bed_type_def = print_config_def.get("curr_bed_type"); assert(bed_type_def != nullptr); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 5f0e9387e8..5748117a6d 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3223,7 +3223,16 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->gui_type = ConfigOptionDef::GUIType::one_string; def->set_default_value(new ConfigOptionPoints{Vec2d(300, 300)}); - + + def = this->add("use_relative_e_distances", coBool); + def->label = L("Use relative E distances"); + def->tooltip = L("Relative extrusion is recommended when using \"label_objects\" option." + "Some extruders work better with this option unckecked (absolute extrusion mode). " + "Wipe tower is only compatible with relative mode. It is always enabled on " + "BambuLab printers. Default is checked"); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionBool(true)); + def = this->add("wall_generator", coEnum); def->label = L("Wall generator"); def->category = L("Quality"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 4ca65b5054..80b1c850b1 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -833,7 +833,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloats, retraction_length)) ((ConfigOptionFloats, retract_length_toolchange)) ((ConfigOptionFloats, z_hop)) - ((ConfigOptionEnum, z_lift_type)) + ((ConfigOptionEnum, z_lift_type)) ((ConfigOptionFloats, retract_restart_extra)) ((ConfigOptionFloats, retract_restart_extra_toolchange)) ((ConfigOptionFloats, retraction_speed)) @@ -853,7 +853,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionBool, auxiliary_fan)) // SoftFever ((ConfigOptionBool, use_firmware_retraction)) - + ((ConfigOptionBool, use_relative_e_distances)) ) // This object is mapped to Perl as Slic3r::Config::Print. diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index fd24f69396..d415e91092 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 1b5cff14fa..73dadae327 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2987,6 +2987,7 @@ void TabPrinter::build_fff() #endif optgroup = page->new_optgroup(L("Advanced"), L"param_advanced"); + optgroup->append_single_option_line("use_relative_e_distances"); optgroup->append_single_option_line("gcode_flavor"); option = optgroup->get_option("thumbnails"); option.opt.full_width = true; @@ -3553,6 +3554,8 @@ void TabPrinter::toggle_options() //} if (m_active_page->title() == "Basic information") { toggle_option("single_extruder_multi_material", have_multiple_extruders); + // Hide relative extrusion option for BBL printers + toggle_line("use_relative_e_distances", !is_BBL_printer); auto flavor = m_config->option>("gcode_flavor")->value; bool is_marlin_flavor = flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware;