From 6023f79be398bcf3b64d445ccb304b0cc45838bd Mon Sep 17 00:00:00 2001 From: SoftFever Date: Tue, 24 Oct 2023 18:49:53 +0800 Subject: [PATCH] add z offset option --- src/libslic3r/GCode.cpp | 16 ++++++---------- src/libslic3r/GCode/SpiralVase.hpp | 4 +--- src/libslic3r/Preset.cpp | 4 +++- src/libslic3r/Print.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 10 ++++++++++ src/libslic3r/PrintConfig.hpp | 2 +- src/slic3r/GUI/Tab.cpp | 5 +---- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 3a99b517f..b0c97f384 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2199,7 +2199,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato this->placeholder_parser().set("first_layer_bed_temperature", new ConfigOptionInts(*first_bed_temp_opt)); this->placeholder_parser().set("first_layer_temperature", new ConfigOptionInts(m_config.nozzle_temperature_initial_layer)); this->placeholder_parser().set("max_print_height",new ConfigOptionInt(m_config.printable_height)); - this->placeholder_parser().set("z_offset", new ConfigOptionFloat(0.0f)); +this->placeholder_parser().set("z_offset", new ConfigOptionFloat(m_config.z_offset)); this->placeholder_parser().set("plate_name", new ConfigOptionString(print.get_plate_name())); this->placeholder_parser().set("first_layer_height", new ConfigOptionFloat(m_config.initial_layer_print_height.value)); @@ -2440,8 +2440,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato if (has_wipe_tower && ! layers_to_print.empty()) { m_wipe_tower.reset(new WipeTowerIntegration(print.config(), print.get_plate_index(), print.get_plate_origin(), * print.wipe_tower_data().priming.get(), print.wipe_tower_data().tool_changes, *print.wipe_tower_data().final_purge.get())); //BBS - //file.write(m_writer.travel_to_z(initial_layer_print_height + m_config.z_offset.value, "Move to the first layer height")); - file.write(m_writer.travel_to_z(initial_layer_print_height, "Move to the first layer height")); + file.write(m_writer.travel_to_z(initial_layer_print_height + m_config.z_offset.value, "Move to the first layer height")); #if 0 if (print.config().single_extruder_multi_material_priming) { file.write(m_wipe_tower->prime(*this)); @@ -2528,8 +2527,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato DynamicConfig config; config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index)); //BBS - //config.set_key_value("layer_z", new ConfigOptionFloat(m_writer.get_position()(2) - m_config.z_offset.value)); - config.set_key_value("layer_z", new ConfigOptionFloat(m_writer.get_position()(2))); + config.set_key_value("layer_z", new ConfigOptionFloat(m_writer.get_position()(2) - m_config.z_offset.value)); config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z)); if (print.config().single_extruder_multi_material) { // Process the filament_end_gcode for the active filament only. @@ -4093,8 +4091,7 @@ std::string GCode::preamble() position of our writer object so that any initial lift taking place before the first layer change will raise the extruder from the correct initial Z instead of 0. */ - //m_writer.travel_to_z(m_config.z_offset.value); - m_writer.travel_to_z(0.0); + m_writer.travel_to_z(m_config.z_offset.value); return gcode; } @@ -4107,8 +4104,7 @@ std::string GCode::change_layer(coordf_t print_z) // Increment a progress bar indicator. gcode += m_writer.update_progress(++ m_layer_index, m_layer_count); //BBS - //coordf_t z = print_z + m_config.z_offset.value; // in unscaled coordinates - coordf_t z = print_z; // in unscaled coordinates + coordf_t z = print_z + m_config.z_offset.value; // in unscaled coordinates if (EXTRUDER_CONFIG(retract_when_changing_layer) && m_writer.will_move_z(z)) { LiftType lift_type = this->to_lift_type(ZHopType(EXTRUDER_CONFIG(z_hop_types))); //BBS: force to use SpiralLift when change layer if lift type is auto @@ -4128,7 +4124,7 @@ std::string GCode::change_layer(coordf_t print_z) m_need_change_layer_lift_z = true; } - m_nominal_z = print_z; + m_nominal_z = z; // forget last wiping path as wiping after raising Z is pointless // BBS. Dont forget wiping path to reduce stringing. diff --git a/src/libslic3r/GCode/SpiralVase.hpp b/src/libslic3r/GCode/SpiralVase.hpp index 1e29b4992..fb461c201 100644 --- a/src/libslic3r/GCode/SpiralVase.hpp +++ b/src/libslic3r/GCode/SpiralVase.hpp @@ -10,9 +10,7 @@ class SpiralVase { public: SpiralVase(const PrintConfig &config) : m_config(config) { - //BBS - //m_reader.z() = (float)m_config.z_offset; - m_reader.z() = 0.0f; + m_reader.z() = (float)m_config.z_offset; m_reader.apply_config(m_config); }; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 5469b3418..cf2d7f3e3 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -833,7 +833,9 @@ static std::vector s_Preset_printer_options { "printhost_user", "printhost_password", "printhost_ssl_ignore_revoke", "thumbnails", "thumbnails_format", "use_firmware_retraction", "use_relative_e_distances", "printer_notes", "cooling_tube_retraction", - "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming"}; + "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming", + "z_offset" + }; static std::vector s_Preset_sla_print_options { "layer_height", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index d6b6a9663..f38c407e0 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -289,8 +289,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n || opt_key == "wiping_volumes_extruders" || opt_key == "enable_filament_ramming" || opt_key == "purge_in_prime_tower" + || opt_key == "z_offset" ) { - //|| opt_key == "z_offset") { steps.emplace_back(psWipeTower); steps.emplace_back(psSkirtBrim); } else if (opt_key == "filament_soluble" diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index f911d4391..61a5abb48 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3426,6 +3426,16 @@ def = this->add("filament_loading_speed", coFloats); def->mode = comAdvanced; def->set_default_value(new ConfigOptionEnum(SlicingMode::Regular)); + def = this->add("z_offset", coFloat); + def->label = L("Z offset"); + def->tooltip = L("This value will be added (or subtracted) from all the Z coordinates " + "in the output G-code. It is used to compensate for bad Z endstop position: " + "for example, if your endstop zero actually leaves the nozzle 0.3mm far " + "from the print bed, set this to -0.3 (or fix your endstop)."); + def->sidetext = L("mm"); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(0)); + def = this->add("enable_support", coBool); //BBS: remove material behind support def->label = L("Enable support"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 443a76187..d34c992e2 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1117,7 +1117,7 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( // BBS: wipe tower is only used for priming ((ConfigOptionFloat, prime_volume)) ((ConfigOptionFloat, flush_multiplier)) - //((ConfigOptionFloat, z_offset)) + ((ConfigOptionFloat, z_offset)) // BBS: project filaments ((ConfigOptionFloats, filament_colour_new)) // BBS: not in any preset, calculated before slicing diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 31a46c235..53ebb870a 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3121,10 +3121,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line("printable_height"); optgroup->append_single_option_line("nozzle_volume"); optgroup->append_single_option_line("best_object_pos"); - -#if 0 - //optgroup->append_single_option_line("z_offset"); -#endif + optgroup->append_single_option_line("z_offset"); // ConfigOptionDef def; // def.type = coInt,