From 2c279c56488eadc01535c2f188e26e5aca8002e7 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Sat, 24 Feb 2024 20:44:00 +0800 Subject: [PATCH] Add direct adaptive bed mesh support (#4212) * Add direct adaptive bed mesh support * fix Linux build error * update tooltip --- src/libslic3r/GCode.cpp | 22 ++++++++++++++++++++- src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 36 +++++++++++++++++++++++++++++++++++ src/libslic3r/PrintConfig.hpp | 5 +++++ src/libslic3r/PrintObject.cpp | 6 +++++- src/slic3r/GUI/Tab.cpp | 6 ++++++ 6 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index f47038eecb..e9a85a1ea1 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1,4 +1,5 @@ #include "BoundingBox.hpp" +#include "Config.hpp" #include "Polygon.hpp" #include "PrintConfig.hpp" #include "libslic3r.h" @@ -21,6 +22,7 @@ #include "Time.hpp" #include "GCode/ExtrusionProcessor.hpp" #include +#include #include #include #include @@ -2322,7 +2324,25 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato this->placeholder_parser().set("first_layer_print_min", new ConfigOptionFloats({bbox.min.x(), bbox.min.y()})); this->placeholder_parser().set("first_layer_print_max", new ConfigOptionFloats({bbox.max.x(), bbox.max.y()})); this->placeholder_parser().set("first_layer_print_size", new ConfigOptionFloats({ bbox.size().x(), bbox.size().y() })); - this->placeholder_parser().set("in_head_wrap_detect_zone",bbox_head_wrap_zone.overlap(bbox)); + + BoundingBoxf mesh_bbox(m_config.bed_mesh_min, m_config.bed_mesh_max); + auto mesh_margin = m_config.adaptive_bed_mesh_margin.value; + mesh_bbox.min = mesh_bbox.min.cwiseMax((bbox.min.array() - mesh_margin).matrix()); + mesh_bbox.max = mesh_bbox.max.cwiseMin((bbox.max.array() + mesh_margin).matrix()); + this->placeholder_parser().set("adaptive_bed_mesh_min", new ConfigOptionFloats({mesh_bbox.min.x(), mesh_bbox.min.y()})); + this->placeholder_parser().set("adaptive_bed_mesh_max", new ConfigOptionFloats({mesh_bbox.max.x(), mesh_bbox.max.y()})); + + auto probe_dist_x = std::max(1., m_config.bed_mesh_probe_distance.value.x()); + auto probe_dist_y = std::max(1., m_config.bed_mesh_probe_distance.value.y()); + int probe_count_x = std::max(3, (int) std::ceil(mesh_bbox.size().x() / probe_dist_x)); + int probe_count_y = std::max(3, (int) std::ceil(mesh_bbox.size().y() / probe_dist_y)); + this->placeholder_parser().set("bed_mesh_probe_count", new ConfigOptionInts({probe_count_x, probe_count_y})); + auto bed_mesh_algo = "bicubic"; + if (probe_count_x < 4 || probe_count_y < 4) { + bed_mesh_algo = "lagrange"; + } + this->placeholder_parser().set("bed_mesh_algo", bed_mesh_algo); + this->placeholder_parser().set("in_head_wrap_detect_zone",probe_count_y); // get center without wipe tower BoundingBoxf bbox_wo_wt; // bounding box without wipe tower for (auto &objPtr : print.objects()) { diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 39411ee506..6bb4e7aff2 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -881,7 +881,7 @@ static std::vector s_Preset_printer_options { "cooling_tube_retraction", "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming", "z_offset", - "disable_m73", "preferred_orientation", "emit_machine_limits_to_gcode", "support_multi_bed_types" + "disable_m73", "preferred_orientation", "emit_machine_limits_to_gcode", "support_multi_bed_types","bed_mesh_min","bed_mesh_max","bed_mesh_probe_distance", "adaptive_bed_mesh_margin" }; static std::vector s_Preset_sla_print_options { diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 0546dff9b3..0068e33b9b 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1550,6 +1550,42 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(40)); + def = this->add("bed_mesh_min", coPoint); + def->label = L("Bed mesh min"); + def->tooltip = L( + "This option sets the min point for the allowed bed mesh area. Due to the probe's XY offset, most printers are unable to probe the " + "entire bed. To ensure the probe point does not go outside the bed area, the minimum and maximum points of the bed mesh should be " + "set appropriately. OrcaSlicer ensures that adaptive_bed_mesh_min/adaptive_bed_mesh_max values do not exceed these min/max " + "points. This information can usually be obtained from your printer manufacturer. The default setting is (-99999, -99999), which " + "means there are no limits, thus allowing probing across the entire bed."); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionPoint(Vec2d(-99999, -99999))); + + def = this->add("bed_mesh_max", coPoint); + def->label = L("Bed mesh max"); + def->tooltip = L( + "This option sets the max point for the allowed bed mesh area. Due to the probe's XY offset, most printers are unable to probe the " + "entire bed. To ensure the probe point does not go outside the bed area, the minimum and maximum points of the bed mesh should be " + "set appropriately. OrcaSlicer ensures that adaptive_bed_mesh_min/adaptive_bed_mesh_max values do not exceed these min/max " + "points. This information can usually be obtained from your printer manufacturer. The default setting is (99999, 99999), which " + "means there are no limits, thus allowing probing across the entire bed."); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionPoint(Vec2d(99999, 99999))); + + def = this->add("bed_mesh_probe_distance", coPoint); + def->label = L("Probe point distance"); + def->tooltip = L("This option sets the preferred distance between probe points (grid size) for the X and Y directions, with the " + "default being 50mm for both X and Y."); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionPoint(Vec2d(50, 50))); + + def = this->add("adaptive_bed_mesh_margin", coFloat); + def->label = L("Mesh margin"); + def->tooltip = L("This option determines the additional distance by which the adaptive bed mesh area should be expanded in the XY directions."); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(0)); + def = this->add("extruder_colour", coStrings); def->label = L("Extruder Color"); def->tooltip = L("Only used as a visual help on UI"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index c3a48cd9c7..4d1d8112ac 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1224,7 +1224,12 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( ((ConfigOptionBools, activate_chamber_temp_control)) ((ConfigOptionInts , chamber_temperature)) + // Orca: support adaptive bed mesh ((ConfigOptionFloat, preferred_orientation)) + ((ConfigOptionPoint, bed_mesh_min)) + ((ConfigOptionPoint, bed_mesh_max)) + ((ConfigOptionPoint, bed_mesh_probe_distance)) + ((ConfigOptionFloat, adaptive_bed_mesh_margin)) ) diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index d7835b0dbb..fc3c41803c 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -1156,7 +1156,11 @@ bool PrintObject::invalidate_state_by_config_options( || opt_key == "sparse_infill_speed" || opt_key == "inner_wall_speed" || opt_key == "internal_solid_infill_speed" - || opt_key == "top_surface_speed") { + || opt_key == "top_surface_speed" + || opt_key == "bed_mesh_min" + || opt_key == "bed_mesh_max" + || opt_key == "adaptive_bed_mesh_margin" + || opt_key == "bed_mesh_probe_distance") { invalidated |= m_print->invalidate_step(psGCodeExport); } else if ( opt_key == "flush_into_infill" diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 7e41d32217..b1f4dbbf0f 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3561,6 +3561,12 @@ void TabPrinter::build_fff() optgroup->append_single_option_line("extruder_clearance_height_to_rod"); optgroup->append_single_option_line("extruder_clearance_height_to_lid"); + optgroup = page->new_optgroup(L("Adaptive bed mesh")); + optgroup->append_single_option_line("bed_mesh_min", "adaptive_bed_mesh"); + optgroup->append_single_option_line("bed_mesh_max", "adaptive_bed_mesh"); + optgroup->append_single_option_line("bed_mesh_probe_distance", "adaptive_bed_mesh"); + optgroup->append_single_option_line("adaptive_bed_mesh_margin", "adaptive_bed_mesh"); + optgroup = page->new_optgroup(L("Accessory") /*, L"param_accessory"*/); optgroup->append_single_option_line("nozzle_type"); optgroup->append_single_option_line("nozzle_hrc");